initially started as a Geocities website when I was in 6th grade. Over the years, it has slowly evolved into a place where I can practice and become familiar with web development as it progresses. I started out coding with Microsoft Frontpage, then moved to Dreamweaver. Initially, there was very little coding, and it was all WYSIWYG. However, as I learned more, I could make it more interactive.

I incorporate drawings and blog posts to keep those that are interested updated. Through the evolution of the website, I was forced to learn HTML, PHP, CSS, XML, jQuery, javascript, and the handling of MySQL Databases. I've put online some code samples.
2018: Jan | Mar |
2017: Mar | Apr |
2016: Jan |
2015: Jan | Feb | Apr | May | Jun | Aug | Sep | Oct |
2014: Jan | Feb | Mar | May | Jun | Sep | Nov | Dec |
2013: Feb | Mar | Apr | May | Jul | Aug | Sep | Nov | Dec |
2012: Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Nov | Dec |
2011: Jan | Feb | Mar | Apr | Jun | Jul | Sep | Oct | Nov | Dec |
2010: Sep | Oct | Dec |
2009: Mar |
2008: Jan | Feb |
2007: Sep | Oct | Nov | Dec |
Looking for even older posts?
The following are hosted on a or Platform:
2007: Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov |
2006: Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
Creating a Python Script to Email Pictures of Ryan Gosling Each Morning
I've a friend who's a big fan of a couple of celebrities (Ryan Gosling, Chris Hemsworth, and Silja Norendal). He'd been throwing out the idea of making a program which would email him a picture of one of them every morning.  He'd asked me how to do it and I did a bit of research and came up with a quick estimate. I knew it would be a python script, and I knew it would have to use a cron job of some sort (I'd never worked with cron jobs but had an interest in them). A cron job is a way you can program a certain file or program to run repeatedly every so often. I'd made something similar (Mara's fake twitter account) a while back, but instead of using cron, I'd just scheduled a task on my computer. The downside of this is that if my computer was not on, the program would not run. You run a cron job on a server (which I have for this website), and by using a cron job I would be able to have it run regardless of whether or not my personal PC was on.

I was sitting at a bar with this friend, and after a few drinks he started asking questions like "how many hours would it take" and "what would you charge per hour". We threw the estimate around and it ended up being $120 to get this done completely. We shook on it right there, with five witnesses. However, I knew this friend was always up for a bet, so I offered him the chance to double or nothing it, meaning I'd either do it for free or he'd pay me $240 to do it. He accepted. We flipped a coin, and, as he often does, he came out on top and I did it for free. To be honest I'm glad that happened, as I would have felt bad accepting $240 for this. Plus, I tend to put a lot more effort into something if I'm doing it for myself rather than doing it for somebody else. Because this was now just on me, I was much more inclined to take a bit of extra time and make sure it's solid. The following is a breakdown of what I did, and how I got it working.

Automatically Sending an Email with a Python Script Using a CronJob:

I broke it down into the following parts
Pull a random image of one of the celebrities:
This one was a bit easy. Initially we were envisioning it would be a random image pulled off of google images every day. However, we settled that we could have 20 images of each person (60 total). Therefore, he'd start seeing repeats on day 61. This made it a lot easier to code, and still has enough variation that he'd not get bored. I found 20 pictures of each celebrity online, and saved them to my server, labelling them accordingly (ryan_1, ryan_2, etc) so that it would be easy to programmatically retrieve the names.
I retrieved the names using the following lines in python:

dayOfYear = #which day of the year it is:0-364
prefixes = ['silje','ryan','chris'] #all files are named silje_2,ryan_5,chris_1, ranging from 0-19.
prefix=prefixes[dayOfYear%3] #get the day of the year, mod 3. This will give us a number which indicates whether we show silje, ryan, or chris today
picToUse=((dayOfYear)/3)%20 #get which picture we want (0-19). Divide by three because this rounds down if it's not a whole number.
filename=prefix+"_"+str(picToUse)+'.jpg' #create the filename "aka silje_4.jpg"

Send an email:
I had done this before with Mara's twitter program, so it was possible, and not that difficult. However, I ended up using something completely different, as somebody had already done a lot of the hard work (see website link in next section). I was able to create a new gmail account just for this which I use to send the emails.

Attach the image so that it would appear in the body of the email:
My first instinct was to use straight html to just display the image using an tab. However, this resulted in an emailing containing the html tag (instead of the image). A google search lead me to this website, which had the basics for embedding an image in an email with python. I did a copy/paste and modified what I needed to, and had that solved.

Schedule a server to run this python script using a cron job:
This was the most frustrating part (though it shouldn't have been). I decided that I'd send it at 4:30am Monday-Friday.  Even after googling, there were  a couple of syntax issues that prevented me from getting the python script to work. Eventually I got the following to work:
30 2  * * 1-5 /usr/bin/python /path/from/home/to/my/ To explain the cron settings in detail, you can check out this helpful page.
30: This will run 30 minutes past every hour it is specified to run.
2: This should only run on hour 2 (2am) of every day specified. Though I wanted the email to send at 4:30 am (after he went to bed but before he woke up), I realized the server exists in a different timezone than I do; 2AM there is 4AM here.
1-5: Run on the first through fifth day of each week (M-F)
I then had to specify the path to the program that should run the script, and the path to the script.

I added in a couple more additions. Mainly, I made a giant list of different possible subjects for the email, and select one at random each day as a little bonus.
That's about it. Each M-F he now gets an email. He's also mentioned it to some others, who requested to get the emails as well. As of now there are 7 or 8 people getting emails.

It was a a fun project, and a neat way to learn about cron jobs. The source python file I created can be found here.
Untitled Document