• CS 4820 Notes
  • Projects from Old Site
  • About Me
  • Archives
  • Categories
  • Archive for February, 2012

    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" --bwlimit=15 /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 --bwlimit=15 /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.

    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