Using a PATA cable for Raspberry Pi B+ GPIO pins

This is not a very impressive discovery… but I figured out that with a (very little) bit of work, a PATA ribbon cable works perfectly with the Raspberry Pi B+!

However, as you can see here, PATA cables have one pin sealed off, which blocks it from plugging in to the GPIO pins on the Pi.

IMG_20141226_104436

As it turns out, it is just a thin piece of plastic, and has a usable connection underneath.

I used the nice ghetto method of hammering a nail into it.

IMG_20141226_104557

And there you have it – a nice ribbon cable that fits perfectly into the Pi GPIO pins.

IMG_20141226_104619IMG_20141226_104634

Also note – If you have a case like mine, you might have to break off the top of the PATA connector for the lid to fit properly.

Git Dependencies in Gradle

I found it a pain to get git dependencies working in Gradle, so I decided to write this ugly blog post for my future self and possibly some other desperately-searching Android developers.

The problem:

Including git project dependencies (e.g. a common library among your apps).

The solution:

Add this to your root build.gradle:

 

To your root settings.gradle:

 

To your app build.gradle:

 

And that is it!!

To update the library, you can just go to the root build/library/ and run a git pull.

Thanks goes to:

ajoberstar for suggesting the Grgit.clone method (http://stackoverflow.com/questions/13719676/gradle-how-to-clone-a-git-repo-in-a-task)

athor for explaining how to neatly include projects in settings.gradle (http://stackoverflow.com/questions/25186187/gradle-module-and-git-submodule)

 

SIMPLIFY ALL THE FRACTIONS

Simplify 120546/54201 into it’s lowest terms. By using the normal “eyeball” method, this would basically impossible (or just very very painful) to calculate.

However! Using Euclid’s Algorithm, it is actually very simple to figure out, even by hand.

I liked the algorithm, so I wrote this little program to calculate it.

In action:

Therefore the greatest common divisor is 3, so the simplified fraction is 40182/18067. As proven by Euclid, these are the lowest terms of the requested rational number. By hand, this would only take 10 simple calculations!

 

How to bake Pi with one cup of Java

So I just watched a video on the calculation of Pi, and was intrigued to write my own little Pi calculator:

In action:

Personally, this clarified my understanding of how Pi is calculated more than just seeing it in that video or in a book.

 

Update:

I punched in the maximum value of iterations (9223372036854775807) and wasn’t really sure how long it would take to compute… I timed 10000 iterations at about 0.6 seconds, so according to my calculations, it will take 1.7 MILLION years to compute pi through that many iterations!

My mind has just been blown through a new perspective of what a massive number 9223372036854775807 really is.