Been a little busy…

With my new job, I haven’t had much time to add much to this website.

So here’s this small perl script I wrote that sends a summary of the weather in SMS format from my iPhone daily.
There was a need, so I figured why not help out those who need the weather forecast =].

use LWP::Simple;
use JSON qw( decode_json );
 
my $lastRun = 0;
open (MYFILE, 'weatherSMS_LastRun');
while (<MYFILE>) {
        chomp;
        $lastRun = $_;
}
close (MYFILE);
 
my ($S,$M,$H,$d,$m,$Y) = localtime($lastRun);
my ($S2,$M2,$H2,$d2,$m2,$Y2) = localtime(time);
if ( $Y2 == $Y && $m2 == $m  && $d2 == $d ){
	exit 0;
}
 
$json = get("https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE?units=ca&exclude=currently,minutely,hourly,flags");
my $decoded = decode_json($json);
 
#ensure we can write the file
open(F,'>weatherSMS_LastRun') || die "Could not open file to mark execution";
print F time;
close(F);
 
my @timeslot = @{ $decoded->{'daily'}{'data'} };
my $forcast = "";
foreach my $f ( @timeslot ) {
	my ($S,$M,$H,$d,$m,$Y) = localtime($f->{"time"});
	$m = $m + 1;
	$forcast .= "$m/$d: ".sprintf("%.3f",$f->{"temperatureMin"})."-".sprintf("%.3f",$f->{"temperatureMax"})."C ".$f->{"summary"}."\n";
}
#printf($forcast);
 
`/Applications/biteSMS.app/biteSMS -send -carrier PHONENUMBER "$forcast"`;

In order to execute this daily, the following plist was used:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.joshho.weatherSMS</string>
	<key>LowPriorityIO</key>
	<false/>
	<key>Nice</key>
	<integer>1</integer>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/bin/perl</string>
		<string>/location to perlscript/weatherSMS.pl</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Minute</key>
		<integer>0</integer>
	</dict>
</dict>
</plist>

Submit it to be executed hourly by running `launchctl load [path to plist]`

Edit
Edits were made to cover the fact that your phone may not always have internet.
(It may be locked/sleeping – which may turn off the wifi?)

Website Maintenance (done)

With the change of my webhost, all my php scripts were moved up from 5.2 to a newer version.

Who knew PHP introduced a ton of changes that practically broke a large number of my apps.
Absolutely ridiculous, but nevertheless, an experience.

I would say all but One app is working just fine.
The app in question works 99% of the time fortunately.

Oh the woes of maintenance of program code.
Wouldn’t it be nice to write it once, and never having to look at it again?

Continued reading >

Website Maintenance

Hi all.

This site may be unavailable in the next upcoming days due to a change in my web hosting company.

Project Euler – Problem 69

Problem 69: Find the value of n < 1,000,000 for which n/φ(n) is a maximum.
Continued reading >

HTML5 – Bejeweled

Hi all.. haven’t been doing much as I’ve been spending my time looking for jobs.

Anyways, here’s yet another completed game – Bejeweled.. this one took almost 4 days and isn’t as awesome as the Popcap one.

The main point of this exercise was the add the ability to click a location on the canvas and have the corresponding (top) object fire an onclick method. The previous version of the engine it’s running on did not support this. As a by-product in doing adding this, this exercise was to dabble my hands in creating a robust solution to onclick() and object mapping. I do not think this was achieved as there is no propagation to parent classes.


You can play it here.

I tried to polish it up with the menu and the layout, but graphics unfortunately aren’t my strength.

HTML5 – Tetris

Not much to say about this one… after completing Pacman, I had an itch to do tetris.. an old favourite of mine.

Completed it in 2.5 days…
At this rate, I’m definitely going to need to step up my productivity for this if I want to make something comparable to Ludum Dare quality.
(2.5.. as a consolation it only included about 14 hours of coding.)

You can play it here.

HTML5 – Pacman

I was talking to a colleague the other day about HTML5-Snake, and somehow the conversation drifted to Pacman…

After a weekend of investigating the Pacman (enemy) strategies, I took a break from doing EulerProject questions and began work on it.
It seemed simple enough: the background was pre-made, (sprites were handmade),  and it seemed very do-able.

It took me 2 days for the base code, +1 for memory/cpu profiling.
It is without sound, but I think it’s quite playable.

You can try it out here.

Continued reading >

Project Euler – Problem 68

Problem 68:
Consider the following “magic” 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.

Continued reading >

Project Euler – Problem 66

Problem 66:
Consider quadratic Diophantine equations of the form:

x^2 – D*y^2 = 1

Continued reading >

Project Euler – Problem 65

Problem 65:

The square root of 2 can be written as an infinite continued fraction.

sqrt(2) = 1+1/(2+(1/(2+1/(2+1/…))))
Continued reading >