Sunday, November 2, 2014

Use iBooks to read Kindle books on a Mac

Amazon has a lot more computer books than the iBook store so I've ended up with quite a few in Kindle over the years. I don't have a Kindle device, just the app for the Mac.
I don't like it. I never have liked it. It just irritates me. For a long time we had to use it because Apple in their infinite wisdom thought iBooks should only exist on the iOS devices but that changed a couple of years back so why am I not reading my Kindle books in iBooks?
Answer Digital Rights Management - DRM. The things that prevents copying even if you're coping it for yourself.

But there's a way around it.

1. Install Calibre http://calibre-ebook.com/download

This is an open source e-book management thing. It has the power to export e-books to other formats but it won't cope with DRM. We need to get rid of the DRM.

We need to add a free and open source plugin to Calibre but we install it in a slightly different way. For me it worked very easily and quickly.

2. Go to Apprentice Alf's page to download the tool. You'll need the Tools not the Alternative tools.

To download, be sure to press the Grey button and un-tick the tick box.




3. Ok now unzip the file somewhere.

4. Start Calibre.

5. Add the plug in.

  1. Select Preferences from the menu-bar.
  2. Select Change Calibre behaviour from the dropdown.
  3. Choose Plugins from the panel.
  4. Select the button: Load plug-in from file.
  5. Navigate the the unzipped files you downloaded.
  6. Open the DeDRM_calibre_plugin.
  7. Select the DeDRM_plugin.zip file.
  8. Choose Add etc and that's it.
No Add books into Calibre and will be DRM free. You can export to Epub and then add to your iBooks library.





The plugin is made by Apprentice Alf I think and there are all sorts of posts on the blog about this

Saturday, October 18, 2014

How to use special character in a Mac like umlaut, acute, tilde and circumflex


The Grave characters: À È Ì Ò Ù à è ì ò ù

Press the following two keys:  option ` and then the character we want.

The Acute characters: Á É Í Ó Ú á é í ó ú

Press the following two keys: option e and then the character we want.

The Circumflex: Â Ê Î Ô Û â ê î ô û

Press the following two keys: option i and then the character we want.

The Tilde: Ã Ñ Õ ã ñ õ

Press the following two keys: option n and then the character we need.

The Umlaut: Ä Ë Ï Ö Ü Ÿ ä ë ï ö ü ÿ

Press the following two keys: option u , and then the character we need.

Friday, September 5, 2014

How to use Interupts in the Raspberry Pi

Excellent.
Just found this.
Now we can do hardware interrupts with the raspberry Pi. A world better than polling.

http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio

How to connect Raspberry Pi to Mac using ethernet cable

Just a note because I did this once, then tried again and could quite remember it.

The default IP address of the Pi is 192.168.2.2

The default IP address of a home network is in the range: 192.168.0.nnn.

Open the Network preferences and set the IP address, subnet mask and DNS server as shown below.



The Airport WiFi is unchanged on my range and the Pi can share the internet via the Mac.

I have done this on Snow Leopard and Maverick. All good. The same should work on Windows I should imagine.

Use Ping in a terminal console window to check the network connection.

ping 192.168.2.2




Monday, August 25, 2014

Raspberry Pi - header pins and BCM pins

This image is taken from Meltwaters Raspberry PI Hardware.




import Rpi.GPIO as GPIO

#Set the GPIO to use the BCM device numbering
GPIO.setmode(GPIO.BCM)

#Set the GPIO to use the Rasperry Pi board header numbering.
GPIO.setmode(GPIO.BOARD)

BCM spec

The spec for the BCM2835 can be found here.


Sunday, June 22, 2014

What is the End of line key in OSX

This has been bugging me for years. What is annoying is that I have not bothered to find the keyboard shortcut for this. How can I be so pathetic.

At work for years it's been Windows and their low-tech, low quality plastic keyboards that are easy to be snobbish about and look down on. But there are two things straight away that I miss when on my Mac keyboard: the 'go to the end of the line' key, and the '#' (I'm using a UK keyboard so I'm not sure if the key is visible on other culture keyboards). I've known the '#' for a long time but not the other.


  • # - Option and 3 together
  • end of line - cmd and right arrow
  • start of line - cmd and left arrow
  • next word - option and right arrow
  • start of page - cmd and up arrow
  • bottom of page - cmd and down arrow
Ok, so here's other ones for text selection:
  • Select text to start of line - put SHIFT with the above line selection (SHIFT + CMD + LEFT ARROW)
  • Select text to end of line - as above but with right arrow.
Try up arrow and down arrow too. They work as expected.

ha! Finally got my act together. I've been using it all day.

Wednesday, December 11, 2013

Note to self - how to do many to many in Entity Framework code-first

I've probably done a handful of EF code-first projects and I always forget how to do the mappings. I always end up looking at old projects and try to figure out what went on. This is a good place to make notes. In my last project I had no idea what I was looking at. Old age has crept up.

I won't go over the whole DbContext Model classes thing,  but in case someone is reading this that isn't familiar, you make a your model classes for your application and they become mapped to your database entities in the Entity Framework ORM world.

So, for example say we have these two model classes amongst our many other model classes:
  • WatchingList
  • Thing


We would then create our DbContext class by creating a class and implementing from DbContext class. For example:

public class MyProjectDbContext : DbContext
{
   // in here we will map our model objects with DbSet<>
   public DbSet<WatchingList> WatchingLists { get; set;}
   public DbSet<Thing> Things { get; set;}

     ... and so on...
}

The above is where all the magic happens. Look elsewhere for a fuller explanation, but in short when we run our app after having done the above, we can then use LINQ to query the database objects, the database will be created for us if it doesn't already exist.

On another note, if it does already exist then we can configure our project to recreate the database on changes. I'm not going to write about that but it's great do developing though probably not great for production systems :)

Many to Many mapping

Anyway, to do the many to many mappings we'll need a

modelBuilder.Entity<WatchingList>()
      .HasMany((w => w.Things).WithMany()
      .Map(m => m.ToTable("WatchingList_Thing")
      .MapRightKey("ThingId")
      .MapLeftKey("WatchingListId"));

Basically,  ThingId and WatchingListId are the columns in the mapping table and the mapping table will be called  WatchingList_Thing

Abstract base classes

If we have some inheritance with these three model objects say,

  • Animal - maybe an abstract base class for the other two concrete classes listed here
  • Dog - inherits/extends the Animal class
  • Cat - inherits/extends the Animal class
If we have these three model classes declared with DbSet in the usual way we will get three tables with those names. We might want to have the table names in the database slightly different to reflect their relationship. We can do that by also overriding the OnModelCreating() method.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Entity<Animal>().ToTable("Animal");
   modelBuilder.Entity<Dog>().ToTable("Animal_Dog");
   modelBuilder.Entity<Cat>().ToTable("Animal_Cat");
}
So we've controlled the naming of tables by EF.






Tuesday, December 10, 2013

XSRF Cross Site Request Forgery attack - ASP.NET MVC

This is a note on the topic that I've been meaning to write for a very long time. I'm a bit old, been around a bit and have worked with a whole range of people. The interesting thing about the XSRF is that I hardly hear it mentioned in the work place. I hope other folk have a better experience. But we just seem to be getting on with the list of functional requirements in time for the next deadline. Perhaps that why it's not talked about enough but it is probably the most 'popular' security vector being exploited by the nasty people.

A quick intro.

In simple terms:

  1. A friendly person A visits our happy site Happy.com and logs in. 
  2. Happy.com site authenticates him and gives him a cookie so that every time he visits us we know he's a good guy.
  3. Unknowingly, friendly guy A visits a bad site Evil.com.
  4. Evil site Evil.com will sneakily return a malicious form tag that will request to our Happy.com site. This malicious code will be allowed to access our server because it is attached to the authentication cookie we gave him and we think that it has already been authenticated.
  5. Bad things can happen.

This works because the authentication cookie is being transported with the request. 
The only way to prevent this is to ensure the form is created by the good user. We use an antiForgery token to help here. 


In the View we put the anti forgery helper:

<% using (Html.BeginForm()) {%>
    <% = Html.AntiForgeryToken() %>


In the controller action we use the ValidateAntiForgeryToken attribute:

[ValidateAntiForgeryToken]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, 

With this asp.net creates a crypto token that can't be created by the Evil user.



Sunday, November 24, 2013

Peter Doolittle talk on "working memory".

Working memory is the part of our consciousness that we are aware of.
1. Allows us to store immediate experiences and a little bit of knowledge
2. Allows us to reach into our long term memory and use it to achieve our current goal

We can remember about 4 things in Working Memory. It has a very limited capacity and we'll forget those things very quickly, seconds, unless we do something with them. We need to process them as they happens.

Working memory Capacity has a long history and is related to some positive effects. People that have relatively high Working memory capacity tend to be good story tellers and tend to be able to reason at high levels.

We need to use Working Memory efficiently to handle the stream of life that comes at us to make sense of it and to achieve our goals. Working memory is really quite small and this talk sheds some light on this interesting architecture. That's how I view it - as an architecture. I think the RAM, cache, disk storage solution in computing is a kind of metaphor for this. But, did our understanding of computer architecture allow us to pin this solution on our mind when actually we are just approximating the solution. Anyway, it's a nice talk.

http://www.ted.com/talks/peter_doolittle_how_your_working_memory_makes_sense_of_the_world.html


Saturday, November 23, 2013

External WD 1 TB will not connect (mount) on a Mac

I have had this problem for a while where the external WD drive doesn't want to connect or be visible on the Mac. I thought it was the cable and fiddled about with that but no. Occasionally it would connect but it didn't follow a pattern, or didn't seem to. I am using the drive as a Time Machine backup.

I may not have fixed it entirely but I can now get it to mount and indeed it has mounted correctly ever since - a few times.

I went to the Disk Utility app and the 1 TB WD drive was being found. It was in the left-hand pane as  shown in the image below.


The below image shows the drive in its working state.
In it's error state it was displaying the text: disk1s3




I went to the Terminal and ran the command:
diskutil list

This provided me with the following:

John-Mac-mini:Volumes John$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            499.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *1.0 TB     disk1
   1:        Apple_partition_map                         32.3 KB    disk1s1
   2:                  Apple_HFS                         1.0 TB     disk1s3



I then mounted the drive:

John$ diskutil mount disk1s3


I noticed immediately that the drive mounted on the desktop and in the DiskUtility app.

Note that the disk identifier may be different for your setup. If you are unsure, look at the disk Utility app where I have drawn the red rectangle.

As I say, I haven't fixed this because at the next power off it may refuse to connect again.

When running distil list again the drive partition is given a name ' My Book Time Machine' as expected. I am not sure if this name is only available after mounting, and therefore it is correctly blank before mounting, or whether that is a part of the problem.

/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *1.0 TB     disk1
   1:        Apple_partition_map                         32.3 KB    disk1s1
   2:                  Apple_HFS My Book Time Machine    1.0 TB     disk1s3