Hackathon and the Digital Pantry of the Future

This weekend I participated in my first hackathon. If you don’t know, a hackathon is some sort of technology competition (usually) where people get together and make whatever they want (sometimes) in 24 hours (usually). Sometimes hackathons are different, maybe based around a specific goal or lasting 48 hours, but this one was free form and 24 hours.

This hackathon is called hackpoly and it’s hosted by the business college at Cal Poly Pomona. It is the first CPP hackathon, but it went quite smoothly. They had great speakers from Space-X and the startup, At The Pool, and after the speeches, the hacking began. 18 teams competed diligently to get their idea off the ground and very few people slept.

I was particularly excited about my team’s project. I was on a team with 3 senior computer science/engineering majors and we had a very ambitious goal. We wanted to create a system that keeps track of what food you have in your kitchen and suggests recipes that you can make with what you have. I would write the iPhone app, Garrett would write the Windows Phone app, Alex would write the Android app, and Steven would write the cloud service and a basic website. To at least some extent, we did all of these things. At the end, the iPhone app and Windows Phone app were at about the same place and had most of the basic functionality in place. The cloud service was also functional at a basic level.

I consider this a huge success. We got a lot done and we realize just how much potential our idea has.

Here’s the idea in a little more detail. The mobile app let’s you put food items from your kitchen into the app by typing them in or by scanning the barcode. The app then sends this data to our cloud server, the cloud server retrieves recipes from the amazing food2fork website, then you see these recipes that you can make with the food you have. To bring this idea into the modern age, we will also be developing a range of different hardware devices which keep track of your different food items and send that information directly to our cloud and back down to your mobile device. For example, a device could keep track of how much milk you have or when your spices have run out. This data would be immediately updated in the apps and website so you would always have an accurate list of recipes to make. Of course there are many times when you have almost enough to make a certain recipe. Say you have all the spices and vegetables to make a popular chicken curry recipe, but you don’t have chicken. The app will suggest that you can make this recipe if you buy some chicken.

I think that having this complete loop of hardware that automatically tracks your food inventory and software that tells you what you can make with it is the perfect combination for the home cook. This is the future of the kitchen.

We will be finishing the software in the next few months and then developing the hardware, likely starting with an internet connected spice rack.

Oh and by the way, we like won hackpoly and stuff. We got first place, as well as the “best use of food2fork” award since they were a sponsor.

Giving a Mac Intelligence

A few years ago I wrote a Mac application that didn’t do anything, except be stealthy. It ran in the background, without a dock icon or a toolbar icon. I could even change the process name so it looked like a system process to anyone casually looking at their processes. This app could’ve been the basis for some malicious code, but of course that was never my intention.

About a month ago I came up with a new way to use this hidden app. I was doing some work on the command line and I came across the “say” command. It gives you access to the speech center in every Mac. Run the command “say hello” and your Mac suddenly says hello to you just as you told it to. I realized that this has some interesting implications if applied correctly.

An application running in the background could spit out all sorts of entertaining things to the listener. I was originally planning on simply using cron to have the Mac say things at specified times. I then realized I could expand this idea using cocoa and making an app that had many more personality trait– erm… features…

Basically the whole premise of this project is to misuse lots of low level and some high level features that have some legitimate uses.

First I figured out how to get notifications of when the computer is about to go to sleep or when it has just woken up. This uses some low level magic that I just copy and pasted from the Apple reference material. This lets me create the main feature. When you close your laptop, the computer says “Nap time!”, then a few seconds later it says “zzzzzzzzz. I’m sleeping”. When you open your laptop it says “I’m awake!”. It’s a very fun and unexpected feature. It also uses applescript to turn the system volume up to 70% before saying those things so you can be assured they’ll be heard.

The problem is that this doesn’t work on computers newer than mine. I’m running OSX 10.6, but I tried it on two computers running 10.8 and the sleep talking doesn’t work. The system allows you to delay sleep, but it doesn’t let any sounds happen. Presumably Apple realized that when someone closes their laptop, they want it to fully shut up. This is of course problematic for this application, but probably good when my laptop starts making noise in the middle of class.

Regardless, I left this feature in place for those who it works for.

Of course it does need some other personality features as well. I realized that I could setup timers, originating when the user opened the computer. After a certain amount of time, a random amount of time, or at a certain time of day, the computer would do something interesting. In one case, I have it ask if you want to hear a joke. If you press yes, then you get a joke from a list of jokes curated by yours truly. If you press no, then you’re told that you’re boring.

Of course, if I tell you the rest of the features then they won’t be very interesting. So I’ll leave the others as surprises to those who I give this software to. I may post it online at some point as well if I can clean it up and make it work more reliably.

Websites for parts and services for building things

Parts and raw materials:

The BEST source. Ever. Period. But fairly expensive: http://www.mcmaster.com/

They’ve got metal (cheap metal but expensive shipping; limited selection of sizes; pretty good alloy selection): http://www.onlinemetals.com/

More metal (haven’t bought from them yet; looks like a great size selection; medium pricing): http://www.speedymetals.com/default.aspx?

Ball bearings (great selection for basic bearings; super cheap): http://www.thebigbearingstore.com/

More ball bearings (haven’t bought from them yet; mediocre website; interesting selection): http://vxb.com/

Super cheap composites, mainly carbon fiber (mediocre website; nice customer support; dirt cheap carbon fiber; good selection): http://www.sollercomposites.com/

Cheap Surplusy stuff (haven’t bought from them yet; looks super cheap): http://www.surpluscenter.com/home.asp

Super cheap RC parts (they have a Chinese warehouse as well as an American warehouse; generally good quality parts; good forum type comment system; often prone to long backorders): http://www.hobbyking.com/hobbyking/store/index.rc

When you can’t find what you need anywhere else… (oh and they have some books too): http://www.amazon.com

It’s best to try to not give into the FIRST corporate machine whenever possible, but sometimes… http://www.andymark.com/Default.asp

Robot motors and wheels: http://banebots.com/

Robot parts (haven’t bought from them yet; looks like good selection; good community of customers): http://www.robotmarketplace.com/store.html

If you want awesome interface electronics, look here (great LED items, screens, and other high level electronics parts and kits): http://adafruit.com/

Huge selection of high level hobby electronics (high margins; slightly non-techy feel; bad product specs): http://www.sparkfun.com/

Electric scooter parts (just like what it says on the tin): http://www.electricscooterparts.com/

Bolts, so many bolts (haven’t bought from them yet; looks cheap; huge selection): http://www.boltdepot.com/default.aspx

Services (haven’t tried any of these yet):

Laser cutting of thinish materials: http://www.ponoko.com/

Waterjet cutting: http://bigbluesaw.com/

3D printing (expensive): http://www.shapeways.com/

How to easily access the raw location data on your iPhone or 3G iPad

Some people (namely David Pogue) have been saying that it is quite difficult to get access to this data without lots of knowledge of Linux. This is not true. Here are some simple instructions on how to get access to the raw location data kept track of by Apple. The basic idea of these steps is: Extract your backup with a backup extractor application, then read the location database file with a database browser.

Step one: Back up your iPhone using iTunes. Do not encrypt your backup as that renders it impossible to get access to the contents. If you don’t want people getting access to the contents then encrypt it. But for the purposes of this exercise, don’t encrypt it.

Step two: Get the iPhone backup extractor application. This application simply finds your backups and extracts them into a readable folder. It is available here: http://supercrazyawesome.com/ This app is only for Macs so if you have a PC or if you use linux then you might want to try this one instead: http://www.iphonebackupextractor.com/ I have not tried it so use it at your own risk.

Step three: Extract your backup! Open up the iPhone backup extractor you downloaded, select “Read Backups”, select the most recent backup from the list, and click “Choose”. Scroll down until you find the text “iOS Files”. Select this and click “Extract”. Select a location to extract it into and click “Extract Here”. It will create a new folder so you don’t have to worry about it spitting files everywhere.

Step four: Get a program to read the database file. I’m using a program called SQLite Database Browser. It is available here: http://sourceforge.net/projects/sqlitebrowser/ Another one that is popular is Base (Mac only): http://menial.co.uk/software/base/

Step five: Go to the place where you extracted your backup. You should see a folder called “iOS Files” or something similar. In that folder go into Library>Caches>locationd. In locationd you should see a file called “consolidated.db”. Open this with the database browser you just downloaded.

Step six: In SQLite Database Browser, click on the “Browse Data” tab. Select “CellLocation” from the “Table” pull-down menu. Here you will see all of the location data points. You can double click on any of the cells in the table to get copy and pastable text. You can copy and paste the longitude and latitude data into google maps to see where it is. This data is not especially useful the way it is because of how inaccurate the location data is. For each data point there is also a “HorizontalAccuracy” field which is most likely in meters. Most of them are between 500 and 1000 for me so that shows how inaccurate it is.

But this data is still very useful for someone who wants to know where you’ve been. Put it all on a map and you have a very clear path of where you’ve been. The point of this blog post is not to show how you can see where you’ve been on a map, but rather to show how easy it is to access this data. All of the software used here has been available for a long time so anyone could have had access to this information for months.

This tutorial may not seem incredibly simple for the average consumer, but this is an extremely simple procedure for any programmer with SQL experience (which is most programmers). There are many virus programmers who would love to have access to millions of people’s location information. This information is just sitting on your hard drive so it would be trivial for someone to add this capability to their PC virus. It only took the O’reily researchers a day to create their mapping application. And if you combine this information with your address book and all of your text messages that are also stored in this backup (in iOS Files>Library>SMS>sms.db) then you get a very good representation of someone and what they’ve done.

How to change the Mac boot logo WITHOUT 3rd party software (by hand)

This is going to be a short post about how to change your Macintosh boot logo/start logo without using software like BootXChanger. Since this software is open-source, I was able to figure out what it was doing and able to replicate it without using the software at all. Whats the point of this you may ask? Why not just use the software? Well its because I’m curious. And its interesting. And I don’t like using shady software, even if it is open-source. Unless I spend the time to figure out what its doing.

BUT FIRST, a warning: Don’t attempt this unless you know your Mac pretty well. I’m not responsible for anything that happens to your Mac, you, your neighbor, your pet fish, or anything else because of these instructions.

The first step is to find an image you want to replace the standard boot logo with. This image MUST be in PNG (portable network graphics) format. It can be any size, but on some Macs (like mine) it will be squished to fit the square space the old logo was in so I recommend using a square image.

The next step is to put the logo in the place where the OS will find it. But FIRST name the logo “BootLogo.png” without the quotes of course. Then you will need to move this logo into “/System/Library/Core Services/”. It will most likely get mad and say you don’t have permission so just put in your password and it should copy in fine.

The next step is to tell the OS that you want a different logo. That can easily be achieved by going into the folder “/Library/Preferences/SystemConfiguration”. Then go to File>Get Info. At the bottom of this you will need to change the permissions so that you can edit the files in this folder. Click the lock at the bottom and enter your password. Click the plus sign and select your user name. Then in the table, change the permissions so that you have read & write privileges. Then click the lock again to save the changes. Then do the same process of changing the permissions to a file in this folder named “com.apple.Boot.plist”. Now open that file in a text editor. TextEdit will work fine. Now add these lines in between the “<dict>” line and the “<key>Kernel</key>” line:

<key>Boot Logo</key>
<string>\System\Library\CoreServices\BootLogo.png</string>

And before each of these lines add in an indent so that these lines line up with the lines below them. Now save this file (it should work because you changed the permissions but it might complain a little).

That should be all you need! Now restart your computer and it should have the custom boot logo instead of that boring grey logo that Apple wants us all to use.

Finding Pi

I’m currently on a mission to write a program that finds pi to a few thousand (or more) decimal places. So far I have encountered many problems with this.

Originally I was going to use the formula pi = sin(1 / ∞) * ∞ * 180

There are many problems with this approach. The first most obvious problem is that there is no way of finding infinity. The way to get around this is to just use a gigantic number (googolplex for example). That would give a fairly good representation of pi.

The next big problem is finding the sine this infinitely small positive number. It is impossible to find a perfect sine of this number because the sine of this number is almost definitely an irrational number. So that means any pi that you find using this method will be wildly off once you get past a few decimal places.

The other big problem is that to find the sine of a number, you have to use pi. This is true because you have have to convert the infinitely small number to radians. This number is in degrees and you have to convert to radians to find the sine of it. To convert degrees to radians, you use the formula: radians = degrees * (pi / 180)

This is basically a problem of the chicken and the egg. You need a perfect representation of pi to find a perfect representation of pi. For more about the sine problem, check out this page: http://www.homeschoolmath.net/teaching/sine_calculator.php

So with all of these problems, this is not a good way of finding pi accurately to many decimal places. However, if you try this formula with 10000 instead of ∞, then you get pi to 9 decimal places with no trouble (my calculator only has 10 digit answers).

The other way of finding pi would be to use this formula: pi / 4 = 1 – (1/3) + (1/5) – (1/7) + (1/11) – (1/13) + …….

This is a much better approach to take, because it allows easy calculation. The only problem with this approach is that it takes many many iterations of this sequence to get an accurate pi. If you try the sequence above, it gives you around 3.2…. The nice thing about computers is that they can do these types of calculations very quickly.

Putting this into action is pretty simple. Here is the source for a processing app that demonstrates this:

[[[Start Code]]]

import java.math.*;
void setup() {
 print("Welcome to the Pi calculator. The program will quit when the calculation is finished.");
}
void draw() {
 PrintWriter output = createWriter("pi_test.txt");
 BigDecimal sequence = new BigDecimal(1);
 BigDecimal two = new BigDecimal(2);
 BigDecimal maxVal = new BigDecimal("3000000000");
 sequence = sequence.divide(new BigDecimal(3), 50, sequence.ROUND_HALF_UP);
 sequence = sequence.ONE.subtract(sequence);
 boolean addsub = true; //true is +. false is -.
 BigDecimal divisor = new BigDecimal(3);
 while(divisor.compareTo(maxVal) == -1) {
 divisor = divisor.add(two);
 if(addsub == true) {
 sequence = sequence.add(sequence.ONE.divide(divisor, 50, sequence.ROUND_HALF_UP));
 }
 if(addsub == false) {
 sequence = sequence.subtract(sequence.ONE.divide(divisor, 50, sequence.ROUND_HALF_UP));
 }
 if(addsub==true) addsub=false;
 else addsub=true;
 }
 sequence = sequence.multiply(new BigDecimal(4));
 output.print(sequence.toPlainString());
 output.flush();
 output.close();
 print("\nCalculation Finished!");
 exit();
}

[[[End Code]]]

This iterates through the algorithm almost 3 billion times. Yet it only gives you 10 decimal places of pi. It also takes 5-10 minutes to calculate, depending on the computer. As you add more iterations, it affects the answer less and less. In other words, once you get up into the billions of iterations, it takes many orders of magnitude more of iterations than when you are in the thousands to get more digits. For example, if you replace the 3 billion with ten thousand, you get 3 decimals of accuracy. When you up it to 1 million, you only get 2 more decimal places!

This makes this way of calculating pi good for systems that can only add, subtract, and divide. But modern computers can do a lot more than that. This leads us to the next best algorithm.

Another formula that can be used is this: pi = 16(1/5 – 1/3(1/5)^3 + 1/5(1/5)^5 – 1/7(1/5)^7 + …) – 4(1/239 – 1/3(1/239)^3 + 1/5(1/239)^5 – 1/7(1/239)^7 + …)

This formula leads to pi a lot faster than the other formula. You can put this formula as is into a calculator and it will give you pi to a few decimal places.

This formula is also a loootttt more cpu intensive! After all, it has to multiply some really long decimals to themselves 10000 times (or however many iterations you chose to run it through). The code is very similar to the first formula. It takes only 100 iterations to get 2 digits (one decimal place). My code doesn’t seem to be working for this though, because when I set it to 1000 iterations, it gave me the same number that I got when I did 100 iterations. Not sure what the problem is here, but heres the code anyway:

[[[Start Code]]]

import java.math.*;
void setup() {
 print("Welcome to the Pi calculator. The program will quit when the calculation is finished.");
}
void draw() {
 PrintWriter output = createWriter("pi_test_v2.txt");

 BigDecimal sequenceone = new BigDecimal(1);
 BigDecimal sequencetwo = new BigDecimal(1);

 BigDecimal two = new BigDecimal(2);
 BigDecimal afifth = new BigDecimal("0.2");
 BigDecimal ttnth = sequenceone.divide(sequenceone.valueOf(239), 500, sequenceone.ROUND_HALF_UP);

 BigDecimal maxVal = new BigDecimal("1000"); //cannot be more than the max int value!

 sequenceone = sequenceone.divide(new BigDecimal(5), 1, sequenceone.ROUND_HALF_UP);

 boolean addsub = false; //true is +. false is -.
 BigDecimal divisor = new BigDecimal(1);
 //first loop
 while(divisor.compareTo(maxVal) == -1) {
 divisor = divisor.add(two);
 if(addsub == true) {
 sequenceone = sequenceone.add((sequenceone.ONE.divide(divisor, 50, sequenceone.ROUND_HALF_UP).multiply(afifth)).pow(divisor.intValue()));
 }
 if(addsub == false) {
 sequenceone = sequenceone.subtract((sequenceone.ONE.divide(divisor, 50, sequenceone.ROUND_HALF_UP).multiply(afifth)).pow(divisor.intValue()));
 }
 if(addsub==true) addsub=false;
 else addsub=true;
 }
 //second loop
 addsub = false;
 sequencetwo = ttnth;
 divisor = new BigDecimal(1);
 while(divisor.compareTo(maxVal) == -1) {
 divisor = divisor.add(two);
 if(addsub == true) {
 sequencetwo = sequencetwo.add((sequencetwo.ONE.divide(divisor, 50, sequencetwo.ROUND_HALF_UP).multiply(ttnth)).pow(divisor.intValue()));
 }
 if(addsub == false) {
 sequencetwo = sequencetwo.subtract((sequencetwo.ONE.divide(divisor, 50, sequencetwo.ROUND_HALF_UP).multiply(ttnth)).pow(divisor.intValue()));
 }
 if(addsub==true) addsub=false;
 else addsub=true;
 }

 sequenceone = sequenceone.multiply(sequenceone.valueOf(16));
 sequencetwo = sequencetwo.multiply(sequencetwo.valueOf(4));
 sequenceone = sequenceone.subtract(sequencetwo);
 output.print(sequenceone.toPlainString());
 output.flush();
 output.close();
 print("\nCalculation Finished!");
 exit();
}

[[[End Code]]]

If anyone has any ideas of what causes this code to not work then give me a holler. I hope this blog post served to be interesting to some people. Hopefully it didn’t fry any brains too much…