• Projects from Old Site
  • About Me
  • Archives
  • Categories
  • Archive for the ‘Programming’ Category

    Website Secondary Host


    2012 - 02.18

    In an effort to boost my website's reliability, I created the following remote mirror system for my website. This system allows for either host to go down without hosting being impacted. With any luck, this will prevent most website outages. This system consists of my primary webserver, hosted in North Bend, WA, and a secondary host: my dorm server running here at Cornell.

    My website is essentially a wordpress installation in addition to some other small php pages. In order to sync the two websites, I use the following script which syncs both the website's filesystem as well as wordpress's MySQL database. This script takes advantage of rsync, so only differences between the two websites are synced. This is essential since my home server has severely limited bandwidth and can't afford a massive transfer every hour.

    #!/bin/sh
    #======================================
    #=== Website synchronization script ===
    #======================================
    
    echo "Syncing website directory with rsync"
    rsync -e ssh -avz --exclude="local" --exclude="Stats.html" --exclude="wp-config.php" /var/www/ nexus:/var/www/
    
    echo "Syncing blog database"
    #Export the wordpress database
    mysqldump -u root -p$PASSWORD blog > /dbtmp/txfr.sql
    #Transfer database via rsync
    rsync -e ssh -avz /dbtmp/ nexus:/dbtmp/
    #Install the remote database
    ssh nexus 'mysql -u root -p$PASSWORD blog < /dbtmp/txfr.sql'
    

    A cron job on my home server runs this script every hour (at 5 minutes past the hour). This can be accomplished by running crontab -e and inserting the line:

    5 * * * * /root/sync_website.sh
    

    In order to switch jeffheidel.com to my backup server when my home server goes down, I use the following python script:

    #!/usr/bin/python
    
    #Script checks if jeffheidel.com is up
    #If down, we reassign the DNS records
    import urllib
    import sys
    import os
    
    def reset():
        print "Executing DNS bypass proceedure"
        os.system("/root/bin/updateip_home.sh")
        sys.exit(0)
    
    try:
        a=urllib.urlopen('http://www.jeffheidel.com').getcode()
        if(a!=200):
            reset()
    except:
        reset()
    
    print "All's good"
    

    The script /root/bin/updateip_home.sh uses FreeDNS's dyndns wget script to set the record for jeffheidel.com to the current IP address. The python script above script runs periodically using cron. Similarly, on my home server, I have a script which periodically runs this wget script so that the DNS record is restored once my home server is restored.

    If things are running normally (both servers are up) you will be able to see my primary server at jeffheidel.com and my backup server at cornell.jeffheidel.com. The only difference between the two websites will be the Server Statistics section.

    Update 02/21/12: My dorm server suffered a hard drive failure last night and is currently offline. I do have a replacement drive so it will be online as soon as I get a chance to reinstall the OS and set everything up again.

    Share

    LatexInk Application for Note Taking with Tablet PC + Latex


    2012 - 02.06

    Here's an interesting program that I just wrote.

    The background for this program has to do with taking notes in my Algorithms class (CS 4820). This class is excellent for taking notes in Latex since it is highly mathematical in nature. Since I spent last semester doing all of my homework in Latex, I am usually able to keep up with the pace of the lecture without trouble. However, I run into trouble whenever the professor draws a figure on the board. While I do have a Tablet PC, there was never really a good way to insert a handwritten element into my notes. Sure, I could draw in paint or some equivalent, save to a file, and then include the file in my latex document, but, by the time I can manage to do all those steps, the lecture will have already moved on. I needed a way to draw and insert within a matter of seconds.

    The program is written in C# and runs on the .NET Windows Presentation Foundation (WPF). This environment was chosen due to the availability of the InkCanvas class, which was extremely easy to use. First, when the program is launched, the user selects the latex file they are working with (Ctrl + O). The program then creates an "images" directory within the same path as the tex file. Then, after a figure is drawn, the user simply needs to push "GEN" or Ctrl + S. This will save the current canvas as a JPG within the images directory and copy Latex code to the clipboard. This code can then be pasted into the document immediately.

    Click to view Full Size Image

    If you would like to use this application, feel free to email me or comment below.

     

    Share

    Work on Dorm Lighting Continues...


    2012 - 01.30

    I have resumed some work on my dorm's light / laser system in my free time (See last year's work here for details). I am currently writing the software and working out a few of the electrical bugs. My next step is beat detection and synchronization. I also want to redo my Android app. More pictures and videos will be uploaded soon.

    Old features from last year:

    • Fluorescent White light
    • UV Black Light
    • Strobe Light
    • Laser Spirograph Projector
    New features:
    • Crude Laser Scanner (servo based) w/ Green & Violet lasers
    • Laser star projector with controllable rotation speed

    Share

    Bike Lights Project


    2011 - 11.25

    This thanksgiving break, I decided to complete the project of adding lights to my bike in order to increase night visibility since I do a good deal of riding after dark. Also, pedestrians could not always see my bike as I approached. Building took about 8 hours. This is the final result:

    My bike features 192 individual LEDs controllable over 6 PWM channels by an ATmega microcontroller. Eight light strips are attached to the bike via superglue and zip ties. All connections are watertight. The electronics are housed within a seat pouch which is water resistant as well. The pouch contains a 4Ah Lithium Ion rechargeable battery as well as an Arduino board attached to a custom built MOSFET shield which directly connects to the lights. It is easily detachable from the Arduino, meaning that I can simply unplug the microcontroller in order to update the bike's firmware.

    I can select flash patterns via a single button mounted on the handlebars. The microcontroller interprets Morse Code from this button in order to determine which flash pattern to select.

     As a bonus, the black wiring I used matches the bike's existing brake lines very well and as a result looks natural.

     With the microcontroller, I can create various flash patterns. In the video below, I illustrate this. I can program additional flash patterns extremely easily and will in the future.


    More photos of the bike and the build process can be viewed here:
    https://www.facebook.com/media/set/?set=a.2706489820637.2150571.1208526308

    Share

    Arduino icm7218 LCD Display Library


    2011 - 03.01

    This is my first attempt at developing an Arduino library. This library, developed for a friend's use, allows an Arduino to easily communicate with a 8 character LCD driver module. The creation of this project involved interpretation of a datasheet's communication protocol and subsequent emulation of this protocol on the Arduino to allow for usage. The result is a module that allows for someone to write numbers to the lcd screen with minimal programming effort. It was quite fun to create and I gained some knowledge about how to read datasheets and implement pre-specified protocols.

    Check out the library, hosted on Google Code, link below:
    https://code.google.com/p/arduino-icm7218-library/

     

    An Arduino hooked up to the icm7218 chip.

    Share