Tuesday, November 1, 2016

ZyXEL Armor Z2 AC2600 is the best router I've owned

I recently reviewed this router on Amazon and thought I'd post it on here as well. I set out to thoroughly test router and push it to its maximum capabilities. As everyone else, I want a router the "just works" without having to constantly reboot it, click through tons of pages, but still be able to have control over more granular features when needed. Well, the good news is that this router exceeded all my expectations!

The Zyxel router comes packaged with everything you need: cables, adapters, etc. It operates on both the 2.4 Ghz and 5 Ghz ISO spectrum at the latest maximum speeds the 802.11 standard supports.

When you first plug in the route and start configuring it, it comes with the latest high-encryption standards enabled. There is no chance that you could accidentally leave this router misconfigured for any hacker to penetrate. The default supplied password is a long random string of characters that would take all the computers in the world a thousand years to crack...suffice it to say, you will be secure.

When it comes to configuring this router, its a breeze! It comes with a web interface for configuring it and allows you to see each computer connected to your Wifi. You are able to set controls for different systems and curfews in an intuitive interface. Most of the technical jargon and confusing settings are hidden unless you click on "expert" mode.

Even in expert mode, for people like myself, it doesn't usually offer enough capabilities. What truly makes this router the ultimate nerd dream, is that the software of the underlying system is based on the OpenWRT router operating system. So essentially, this router is running a high performance version of Linux. I have poked around and customized this router beyond anything you could do with a regular router from one of the main router companies out there.

Whether you are an expert like me, or just a basic user, this is your ideal router. It is secure, easy to set up, and very reliable. I have used it for several months now and never had such good internet speeds. I have yet to reboot this router. My former router, for which I paid $250 from a electronics store, constantly needed to be restarted.

Do yourself a favor, and buy this router.

Thursday, August 20, 2015

Tracking migraines and the world of the Internet of Things

I recently read a post by Ted Benson titled, How I Hacked Amazon’s $5 WiFi Button to track Baby Data, where he sniffs for the ARP request of an Amazon Dash Button to log data. The Amazon Elements Dash button cost only $4.99 so I ordered one immediately.

My idea is to use it to track when I have migraines to better pinpoint things that trigger it. Usually when I get a migraine I am not keen on trying to write it down (although I should) so I thought this may be an easy way to do it. Just press a button!

Once I received my button I started adapting Ted's code. The CloudStich service is incredibly easy to use! I signed up for an account, got a personal URL, and was ready to log information to Google spreadsheets!

Getting the Code to Run:
My biggest hurdle was getting requisite Python libraries installed on my Macbook Pro. To intercept network traffic for the Dash button, Python uses the the Scapy library.

from scapy.all import *

Even after installing scapy, when I tried to import it, I got an error:

import pcapy as pcap ImportError: No module named pcapy
I installed pcap only to get another error for missing the dnet library. Attempting to install it using pip failed to I thought I'd try my favorite package manager, HomeBrew.

 $ brew search dnet  
 libdnet wordnet  
 $ brew install libdnet  
 ==> Downloading https://homebrew.bintray.com/bottles/libdnet-1.12.yosemite.bottle.2.tar.gz  
 ######################################################################## 100.0%  
 ==> Pouring libdnet-1.12.yosemite.bottle.2.tar.gz  
 ==> Caveats  
 Python modules have been installed and Homebrew's site-packages is not  
 in your Python sys.path, so you will not be able to import the modules  
 this formula installed. If you plan to develop with these modules,  
 please run:  
  mkdir -p /Users/me/Library/Python/2.7/lib/python/site-packages  
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/me/Library/Python/2.7/lib/python/site-packages/homebrew.pth  
 ==> Summary  
 🍺 /usr/local/Cellar/libdnet/1.12: 28 files, 476K  

Once I got dnet installed, I also had to run it as root. This is not a big deal for me, but may be a roadblock for some that do not have superuser privileges on their machines.

My next dash button may be put in my mailbox and linked with Pushover.

Thursday, March 20, 2014

Temperatures and Prime Numbers

While driving the other day, I wondered what combinations of numbers will be prime in both degrees C and degrees F. I could only find one and so wondered if there are any others. From what I can tell, in the first million degrees C, there is only one set. Here is the code I used to check with. It relies on a handy module named pyprimes to ease in finding prime numbers. Answer at very bottom.

# python FandC.py 
5 degC, 41 degF 


Monday, September 16, 2013

How To Make Your Browser A Little More Secure

I searched high and low on the internet for a guide to secure my browsing session and disable web servers from preferring insecure SSL sessions. Many websites, such as amazon.com, in an effort to gain better performance, will prefer slightly more insecure methods for establishing a secure SSL session. Unfortunately, I have not found a way to override that preference with the client (browser) preference instead. However, it's probably a better idea to disable any and all weak encryption algorithms in any ways. Two very useful link to verify both a browser and web server's security stance is given below:

Browser accepted security protocols:

Web Server accepted security protocols:

Step 1: 
Stop using browsers that do not support SSL encryption algorithm configuration. (Sorry Chrome)

Step 2: 
Download Firefox, which does allow one to

Step 3: 
Go To: about:config

Step 4: 
Search: security.ssl3.

Step 5: 
Set all to false that do not start with ecdhe or ecdh or dhe.
             Set all to false that contain des, md5, dss, aes_128, rc4, camellia, etc.

My list is:

  • security.ssl3.ecdhe_rsa_aes_256_sha;true
  • security.ssl3.ecdhe_ecdsa_aes_256_sha;true
  • security.ssl3.ecdh_rsa_aes_256_sha;true
  • security.ssl3.ecdh_ecdsa_aes_256_sha;true
  • security.ssl3.dhe_rsa_aes_256_sha;true


Sadly, many websites will not support this, so if you run into trouble, this one will fix it, although RSA seems to be questionable due to the recent security leaks that has been in the news.

  • security.ssl3.rsa_aes_256_sha;true

Monday, August 5, 2013

Store Script Passwords Securely in Mac OS X

I frequently use scripts that contain passwords. Since storing these pose somewhat of a security risk, I started researching ways to not store any passwords in my scripts, but rather in my Mac OS X keychain or some other keychain such as Ubuntu's keychain. Since most of my scripts are python based these days, the following two lines of Python code rely on Mac OS X's 'security' command to read and print a password from your keychain:

1:  import subprocess as sub
2:  password_cmd= ['security','find-generic-password','-s','booger','-g']  
3:  password_dcrypt = sub.Popen(password_cmd,stdout=sub.PIPE,stderr=sub.PIPE).communicate()[1].rstrip().split(':')[1].lstrip().lstrip('"').rstrip('"')  

This can of course be done in shell scripts just as easily:

1: password_dcrypt=$(security find-generic-password -s booger -g 2>&1|perl -lne 'print $1 if m/password: \"(.+?)\"/g')

Of course, if you haven't already added a password item to your keychain, you can easily do so with the security command. However, note that whichever password you set, will be in your command history so use with caution. The better way would be open up the Keychain utility and manually add or change your password.

1: security add-generic-password -a 'My Booger Account' -s 'booger' -p 'Priceless12345%$#!'

Tuesday, June 4, 2013

Ping utility that targets a specific port

Frequently I reboot servers and while I wait for them to come back up, I ping them to see when they are "back up" However, even after I receie a positive ping response back from the server, it still takes a while before SSH is initialized.

I wrote my own python-based ping utility that allows one to ping a specific port on a remote host. The utility has three modes: (1) One time, (2) Infinite, and (3) Set number of times.

 ./port_ping.py hostname port #(one time)
./port_ping.py hostname port -n inf #(indefinitely)
./port_ping.py hostname port -n num #(num times)

(NB: I'm still in the process of cleaning this up and making it pretty. In the future, I am considering making it mimic the standard GNU ping utility's syntax.)


Tuesday, April 30, 2013

Checking your final grades at Auburn...automatically!!!

During finals week, I found myself constantly checking the Auburn University site to see if new grades are posted. At the time, I did not know that they actually only post grades at midnight. I ended up using Python, BeautifulSoup, and other tools to log in and grab the final grades site, parse for new classes, and then send a push notification if new ones were found. Prowl is the only good push notification app for iOS that I'm aware of. If you are using Android, there exists numerous ones and you can modify as needed. To get this script running, put it in a python (.py) file, and run it through your favorite scheduler. I use launchd on my Mac and cron on Linux. Happy finals and may the curve be ever in your favor!
1:  #!/usr/bin/env python  
2:  from BeautifulSoup import BeautifulSoup  
3:  import mechanize, sys, re, time, shelve  
4:  import prowlpy  
6:  shelve_file = 'grades.pyshelf'  
7:  apikey = '123khlkjh1l23kjh12l3kjh13lk12hj3lk12jh31lkj3h213lkjh123' #Prowl API Key  
8:  username   = 'tigerid0012'  
9:  password   = 'imsexyandiknowitlalala'  
10:  a_url    = 'https://ssbprod.auburn.edu/pls/PROD/bwskogrd.P_ViewTermGrde'  
12:  def get_html(username, password):  
13:    br = mechanize.Browser()  
14:    br.open(a_url)  
15:    br.select_form('loginform')  
16:    br['sid']  = username  
17:    br['PIN']  = password  
18:    br.submit();  
19:    br.open(a_url)  
20:    br.select_form(nr=1)  
21:    response   = br.submit()  
22:    return response.read()  
23:  ####  
25:  def parse_grades(html_doc):  
26:    grades = {}  
27:    soup = BeautifulSoup(html_doc)  
28:    for item in soup.body.find('table', { "class" : "datadisplaytable", "summary" : re.compile('This table displays the final\ngrade') }).findAll('tr'):  
29:      if( item.findAll('td', { "class" : "dddefault" }).__len__() > 6):  
30:        ClassTitle = item.findAll('td', { "class" : "dddefault" })[4].getText()  
31:        ClassGrade = item.findAll('td', { "class" : "dddefault" })[6].getText()  
32:        grades[ ClassTitle ] = ClassGrade  
33:        #print ClassTitle.getText() + " " + ClassGrade.getText()  
34:      ####  
35:    ####  
36:    return grades  
37:    #print grades  
38:  ####  
40:  def sendpush(textmsg):  
41:    p = prowlpy.Prowl(apikey)  
42:    try:  
43:      p.add('New Final Grade',"You have a new grade: "+ textmsg, 1, None)  
44:      print 'Success'  
45:    except Exception,msg:  
46:      print msg  
47:    ####  
48:  ####  
50:  def main():  
51:    d = shelve.open(shelve_file, flag='c', protocol=None, writeback=True)  
52:    #print dir(d)  
53:    if d.has_key('num_grades'):  
54:      pass  
55:    else:  
56:      d['num_grades'] = 0  
57:    ####  
58:    d['mygrades'] = {}  
59:    print "Checking Grades"  
60:    d['mygradepage']  = get_html(username, password)  
61:    d['new_mygrades'] = parse_grades(d['mygradepage'])  
62:    d['new_numgrades'] = len(d['new_mygrades'].keys())  
63:    if( d['new_numgrades'] > d['num_grades'] ):  
64:      mykeylist = [diffgrades for diffgrades in d['new_mygrades'].keys() if diffgrades not in d['mygrades'].keys()]  
65:      pushstring = "";  
66:      print "New grade:"  
67:      for classtitle in mykeylist:  
68:        stringy = classtitle + " ("+d['new_mygrades'][classtitle]+")\n"  
69:        pushstring = pushstring + stringy  
70:      ####  
71:      sendpush(pushstring)  
72:      print pushstring  
73:    else:  
74:      print "No new grades"  
75:    ####  
76:    d['num_grades'] = d['new_numgrades']  
77:    d['mygrades']  = d['new_mygrades']  
78:    d.sync()  
79:    d.close()  
80:  #### END main()  
82:  if __name__ == "__main__":  
83:    main()  
84:  #### END if  

Wednesday, February 27, 2013

School Spirit in the Terminal

Some years back I converted an Auburn University logo to ASCII text using an online ASCII text generator and then colorized it using Perl. I place this file in my home directory as an invisible file named .auburn_logo.pl, and call it from my .bash_profile or .profile. It's sure to impress your friends when you pull up a new terminal window.

See code below:

1:  #!/usr/bin/env perl  
2:  use strict;  
3:  use Term::ANSIColor qw(:constants);  
5:  my $auburn = '  
6:                   88888888888                    
7:                   888888888888                   
8:                   88OIIIIIII8888                   
9:                  888IIIIIIIII8888                  
10:                  888IIIIIIIIIII888?                  
11:   888888888888888888888888  888IIIIIIIIIIIII8888  888888888888888888888888    
15:   8888888IIIIIIIII88888888888IIIIIII888~888IIIIIII88888888888IIIIIIIII8888888    
16:   8888888IIIIIIIII8888888888IIIIIIIO88$ 8888IIIIIII8888888888IIIIIIIII8888888    
17:      88IIIIIIIII888  888IIIIIIIO88O  8888IIIIIII888  ~88IIIIIIIII888      
18:      88IIIIIIIII888 888IIIIIIIO88~   ~888IIIIIII888 ~88IIIIIIIII888      
19:      88IIIIIIIII888 888IIIIIIII88O    O88ZIIIIIII888 ~88IIIIIIIII888      
20:      88IIIIIIIII888888IIIIIIII888     O888IIIIIII888~88IIIIIIIII888      
21:      88IIIIIIIII88888IIIIIIII88888888888888888OIIIIIII88888IIIIIIIII888      
25:      88IIIIIII888IIIIIIII8888888888888888888888888IIIIIIII888IIIIIII888      
26:      88IIIIII888IIIIIIII888888888888888888888888888IIIIIIII888IIIIII888      
27:      88IIIII888IIIIIIII888            888IIIIIIII888IIIII888      
28:      88IIII888IIIIIIII888             888IIIIIIII888IIII888      
29:   8888888888888IIIIIIII88888888888      88888888888IIIIIIII8888888888888    
30:   888888888888IIIIIIII888888888888      888888888888IIIIIIII888888888888    
34:   88888888888888888888888888888888      88888888888888888888888888888888    
35:      887IIIIIIIII888$                 ?888IIIIIIIIII88      
36:      888IIIIIIIIIII888O               8888IIIIIIIIIII888      
37:      888IIIIIIIIIIII888888           88888IIIIIIIIIIIII888       
38:       888IIIIIIIIIIIIIIIO888888888888888888888887IIIIIIIIIIIIIII888       
43:           888888$IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII888888            
44:             888888888$IIIIIIIIIIIIIII$888888888              
45:                888888888888888888888888                 
46:  ';  
47:  my @auburn = split(//,$auburn);  
48:  foreach(@auburn){  
49:       if($_ eq 'I'){  
50:            print $_, RESET;  
51:       }else{  
52:            print BLUE $_, RESET;  
53:       }  
54:  }  

Sunday, October 14, 2012

Using Audacity as an Oscilloscope

A good oscilloscope is hard to afford. Spending money on a mediocre one doesn't seem to justify the stiff cost of even low-end scopes. In the meantime, I found a workaround! :-) Why did I need an oscilloscope? I've been wanting to crack my truck's keyless entry transponder code for a while now. I finally got around to it and succeeded with the help of a $5 315 MHz wireless receiver module from sparkfun.com, an old headphone cable, and a free audio editing program named Audacity. Below is a screenshot of the captured code:

Audacity Sound Editing Software
With an old broken headphone (2.5 mm) jack, I connected the receiver's output to the input of my laptop. 

Note: This could be dangerous! Do not do this unless you know what you're doing. Connecting a high powered circuit to your computer's sound card will probably fry the sound card and your computer! 
Once connected, I powered up the receiver from a USB port and hit record while simultaneously hitting the lock button on my truck transponder. Above is a screenshot of the output.

From the captured output, I was able to determine a series of 1's and 0's.

The next step is being able to reproduce the code with microcontroller and send it to a 315 MHz transmitter. The possibilities for this are endless. This also allows me to control multiple vehicles with a single device. More to come soon!

Monday, October 1, 2012

Simulink on Arduino!

From the Mathworks website:

Run Simulink models on supported target hardwareSimulink provides built-in support for prototyping, testing, and running models on low-cost target hardware, including Arduino®, LEGO® MINDSTORMS® NXT, PandaBoard, and BeagleBoard. You can design algorithms in Simulink for control systems, robotics, audio  processing, and computer vision applications and see them perform with hardware. This hardware support is also available in MATLAB and Simulink Student Version.


Once I get it working, I'll post a short tutorial.

Thursday, September 20, 2012

Cool Matlab discoveries!

I just discovered two very neat and useful Matlab functions on http://people.csail.mit.edu/jskelly/blog/

1) Matlab has the ability to take a symbolic expression and convert it to Latex. I find this especially useful when I solve a complex problems and the output has a lot of different braces, etc. Simply render the Latex output and see the output more "Mathematically".

2) Matlab also has hash tables similar to Perl!

EDU>> variable = containers.Map

variable = 

  containers.Map handle
  Package: containers

        Count: 0
      KeyType: 'char'
    ValueType: 'any'

  Methods, Events, Superclasses 

And adding values:
EDU>> variable('Peter') = 'Paul';
EDU>> variable

variable = 

  containers.Map handle
  Package: containers

        Count: 1
      KeyType: 'char'
    ValueType: 'any'

  Methods, Events, Superclasses

EDU>> variable('Peter')

ans =


Sunday, August 19, 2012

The Sentients: Making an Exception

A quick story I had to write for my Mobile Robotics class. We had to write a Sci-Fi story involving a team of mobile robots.

Making an Exception

A swarm of robotic creatures, known as Sentients, is the sustaining force behind our planet’s civilization. They are responsible for transporting and moving everything on the planet to its destination. They are small and modular, run off the energy transmitted by the sun, and have a device in them that cancels the planet’s gravitational effect on them. This allows them to fly very efficiently.

One Sentient could easily fit in the palm of one’s hand. It has a small hand like claw with full degrees of freedom in any direction. It looks like something between a human hand and the tentacles of an octopus. When larger deliveries were to be made, say for example delivering and moving a piano, dozens of Sentient robots would form an enclosing structure around the package, and in unison, pick the item up and deliver it to its destination.

These creatures, although no one knew who created them, had enough intellectual capacity to easily follow directions and properly place a piece of furniture in a room, for example. In a sense they were like well-trained animals. The one great exception to the animal kingdom was that these little machines could not be tamed. They had a sense of morality and would never do something that could or would harm someone. At night, when they had no energy source, they all disappeared. When the orange rim of our slowly dying sun peeked its head over the horizon at dawn, the whirling buzz of the Sentients would be heard and the world would come back to life.

How these beings were created, repaired, or died (if they ever did), no one knew. It seemed that they were indestructible. Sometimes teenagers would attempt to shoot the Sentients with a Particlegun, but none of the pellets could damage it. It was as if some force, maybe the same one that was neutralizing gravity, was also protecting them. Whether they wore out and “died” was also a mystery. Since they all vanished in the hazy dusk, no one knew if they wore out and were replaced or simply immune to time itself. All the Sentients looked the the same, although on close inspection, each one is covered with a golden holographic shimmer representing unique fractal patterns.

The Wise Elders of the planet had set out repeatedly throughout the millennia to study them, but no one could understand the mystery of the Sentients. Common people took them for granted and believed they were a gift from a reclusive Wise Elder named Nicholas Tieslat who lived thousands of years ago. He was supposedly exiled by his contemporaries that all worked for the Evil One, Isiah Edisoll.

On a cool summer evening, Ladrick Vermilliona was leisurely walking to Lake Seneca when he found a single sentient lying upside down on the sailing team’s pier. There seemed to be no motion in it. He picked it up, it was quite heavy for such a small thing, feeling like it weighed as much as 5 liters of water. The little creature was motionless. Somehow it didn’t escape into the dusk.

He decided to take it home. There was a strange irony carrying it. They were always there, ready to carry something at a human’s request. It was long rumored that the sentients were energized by the sun. Not in the conventional way, but rather by recently discovered gravitational waves with sub-yoctometer wavelengths. Some of the Wise Elders believed that these waves came from the sun and was emitted by elemental constructs of all that exists.

By the time Ladrick got home he lost interest in the Sentient and decided to leave it on his kitchen table and go to bed. Tomorrow was Saturday and he would have all day to look at it.
Ladrick’s morning alarm’s soft whir woke him up. There was a hot cup of coffee next to his bed. He picked it up and smelled the rich earthy aromas. The coffee was from Angola, the best coffee the planet has to offer. Some unknown sense alerted him to some other presence. In the doorway to the kitchen was the Sentient he had picked up. Its faint whirring sound alerted his senses. He felt a sense of relief and disappointment. No one has ever seen an inanimate Sentient. The Sentient must have made him coffee. He got up, coffee in hand to inspect the Sentient a little closer.

The room started to spin. All of a sudden Ladrick’s body was racing towards the floor. The Sentient came quickly to his aid, but his weight was too much and he hit the floor with a loud thud. He momentarily awakened as the Sentient’s single gripper softly dropped his phone on his cheek. It was dialing 1009 for the emergency response. The Sentient then disappeared.
“Good Morning, -” the operator answered.
“Help! I passed out and fell on the floor...”
“We’re sending an emergency team right away,” the voice replied.
Ladrick blacked out again and 5 minutes later a group of several dozen Sentients appeared in the doorway ahead of the EMTs.

Days after Ladrick’s surgery to remove a brain tumor, he kept wondering how he’s alive. Doctors say the tumor blocked blood flow to his brain and if he had called 1009 any later, he would have died. Why or how he was able to dial is a mystery to him. But in the back of his mind there was something bothering him. Some memory of the night before, now missing due to his surgery, that could provide the answer as to how he’s alive.

Sunday, July 15, 2012

Tracking an LED with OpenCV

I have become very interested in using webcams to track objects and calculate their relative position in a space. My trusty friend OpenCV 2.4 came in handy. I used Harpia on Ubuntu 10.04 to generate some old, flaky code to track the green LED on an Arduino Mega. I pulled all the functions out of the Harpia code and put them in my own C program. (Code on Github shortly) Since LEDs have a pretty steady color, I took a photo of the LED with the webcam I was using, and then calculated the color value the LED was emitting. From this, I can output X,Y coordinates for the LED in the frame. Below is a quick video I made showing the tracking interface:

Thursday, July 12, 2012

Gauss-Seidell Iterative Method for Power Flow Analysis

Probably the most exciting and interesting thing I learned this Summer in school is using the Gauss-Seidell Method to solve a Power Flow Analysis problems

The Matlab code below is posted on Git.

{edit} Code is not working. I get a slightly different answer than what I'm supposed to. I've got to run through it but I'm a bit too busy with school right now. :-)

Thursday, May 3, 2012

Good Engineering Student Study Habits

One of the lessons any Engineering student learns is that no matter how smart you think you are, there will always be one or more classes that will force you to work hard. For most, that means most classes. Here are some lessons I've learned. They are common-sense, but not commonly followed.

  1. Take Notes! Hearing, writing and seeing new concepts and information is crucial to learning. Pay attention, interact with the instructor, and take copious notes.
  2. Review. Review class notes every day some time after class. Every day you go to 3 or more technical classes learning things that you probably never imagined existed before. When you learn things in class, they are in your short-term memory, but with so much information to cram into your brain, much is easily lost without further review. A good practice is to create time slots for each class you attended each day and review your notes for that class. You'll find places where you didn't finish out a sentence or equation. Fill in these blanks while the information is still fresh in your mind. Professors are notoriously bad at writing their explanation on the board. Write in your own explanations into your notes. My notes are usually filled with lots of equations, plots and diagrams, but little explaining them. When you make the mistake (like I have) of waiting until the night before your exams to start studying and reviewing your notes, they will be illegible and not as useful.
  3. Study Groups. Study groups can be both hazardous or extremely helpful. The key is to find people to study with that are willing to work hard. Many people are lazy and only come to study groups because they want to copy homework assignments or have others explain to them information they never cared to learn during class. Find hard-working, motivated individuals. It is a bit selfish to say it, but find people who are your peers or smarter than you. They will keep you pushing yourself to new intellectual limits.
Time for me to get back to studying for my finals, but I'll work on this list and expand it as necessary.

Thursday, April 26, 2012


Our Electrical Engineering Department at Auburn University has a list service that they use to send out email notifications. Usually it's general stuff such as recruitment events, new classes opening up, etc. The other day, when I opened up an email from them, Google Chrome thought the email was in Estonian! See screenshot below... :-)

Monday, March 26, 2012

Innovative Humanitarian Products Organization

I am able to proudly say I'm part of the IHPO (Innovative Humanitarian Products Organization). We design and develop products that are cheap and able to make a difference in the developing world. Our first product was an electrical device (our founder, Grant Moore is an Electrical Engineering student), which uses salt water to make chlorine for sterilizing water, etc.

We are currently entered into a competition to win $5000 and need everyone's help. The competition gives $10,000 for the presentation with the most views, and $5000 for the 2nd - 5th places. We are currently in 5th place, but to solidify our win, we'd still love as many views as possible. Watch the presentation below or click the link:


Monday, March 12, 2012

Keep track of your IP address and internet connectivity

Below is some code I wrote to email me whenever my computer's IP address changes and log it to a file. I nifty side effect is it keeps track of when my internet connection is down as well. Copy this code and insert your own email address and run on a schedule such as cron.

Wednesday, March 7, 2012

No post for today's Computer Systems

We covered the all to crucial and important interrupts in Computer Systems today but alas, I was still occupied with Digital Electronics and the wonderful and sometimes mysterious world for transistors and couldn't take real good notes. For my own review and the benefit of the world, I'll write up a summary of HCS12 interrupts when time permits. Sorry...

Tuesday, March 6, 2012

Using Google Command Line Tools to post my Computer Systems Notes

Below is some code I wrote to post my Computer Systems notes online every day after class:

  1 #!/usr/bin/env perl
  2 use strict;
  3 use warnings;
  5 unless(defined $ARGV[0]){
  6    print "$0 [file to post]\n";
  7    exit;
  8 }
  9 my @date = ($1,$2,$3) if $ARGV[0] =~ m/Computer_Systems_(\d{4})(\d{2})(\d{2}).txt/g ;
 10 my $title = "Computer Systems Class Notes ".join('/',@date);
 11 my @infile = `cat $ARGV[0]`;
 12 my @template = `cat blank.html`;
 13 # Get rid of blank lines...
 14 my $tmp = pop(@infile);
 15 while($tmp =~ m/^\s*$/g){
 16    $tmp = pop(@infile);
 17    #print "tmp got $tmp\n";
 18 }
 19 push(@infile,$tmp);
 20 open(FH,">$ARGV[0].html");
 21 foreach(@template){
 22    if(m/{{{TITLE}}}/g){
 23       $_ =~ s/{{{TITLE}}}/$title/g;
 24    }
 25    if(m/{{{BODY}}}/g){
 26       $_ =~ s/{{{BODY}}}/@infile/g;
 27    }
 28    if(m/^\s*$/g){
 29       next;
 30    }
 31    print FH "$_";
 32 }
 33    close(FH);
 34 #  
 35 print "google blogger --blog \"Renaissance Engineer\" post --title \"$title\" --tags \"HCS12, Assembly, Computer, Systems, googlecl, development\" $ARGV[0].html\n";
 36 system("google blogger --blog \"Renaissance Engineer\" post --title \"$title\" --tags \"HCS12, Assembly, Computer, Systems, googlecl, development\" $ARGV[0].html");
 37 unlink("$ARGV[0].html");

Class Notes 2012/02/13

; #1 Write a program to compute the following
;A1 = (B1 - C1) - (D1 + 8)

;Use only direct/extended addr. for all memory references.

ldea B1; A=B1
suba C1 ; A = (B1-C1)
ldab D1 ; B = D1
addb #8 ; B = (D1 + 8)
sba ;
staa A1 ;

;Use only constant offset indexed addr. for all memory references.

ldx #A1
ldaa 1,x ;A=B1
suba 2,x ; A=(B1-C1)
ldab 3,x ;B=D1
addb #8 ;B= D1+8
sba ;A=(B1-C1) - (D1 + 8)
staa 0,x ; staa x

;Use auto-increment indexed addr. for all mem references.

ldx #A1 ;
ldaa 1,+x ; A = B1
suba 1,+x ; A = (B1 - C1)
ldab 1,+x ; B = (D1)
addb #8 ; B = (D1 + 8)
sba ; A = (B1-C1) - (D1 + 8)
staa 3,-x ; A1 = A

;Use register offset indexed addr. for all mem references.
ldx #41
ldab #1
ldaa b,x ; A = B1
ldab #2
suba b,x ; A = (B1 - C1)
ldab #3
suba b,x ;A = (B1 - C1) - D1
suba #8 A = B1 - C1 - D1 - 8
ldab #0
staa b,x A1 = A

;Define 2 20-byte arrays,
; 1) Copy one byte at a time, using indexed addressing but without using auto-increment (or decrement).

ary1 ds.b 20
ary2 ds.b 20

ldab #20
ldx #0
ldaa ary1,x ;ary1[i]
staa ary2,x ;ary2[i]
in x
dbne b,loop

2) Copy one byte at a time, using auto-increment.

ary1 ds.b 20
ary2 ds.b 20
ldab #20
ldx #ary1
ldy #ary2
loop: ldaa 1,x+ ;movb 1, x+,1,y+
staa 1,y+ ;movb 1, x+,1,y+
dbne b,loop

3) Copy one word at a time using auto-inc.
ldab #10
ldx #ary1
ldy #ary2
loop: mov2 2,x+,2,y+
dbne b,loop

Class Notes 2012/02/10

ORG $800
vec1 dc.b 1,2,3,4,$FF
vec2 dc.b 0, $FF, 3, 5, $80
count ds.b 1
ORG $4000
ldx #vec1 ; x->vec1
ldy #vec2 ; y -> vec2
ldab #5 ; init loop counter
clr count ; clears the count
loop: ldaa 1,x+ ;vec1[i] -> A
cmpa 1,y+ ;compare vec1[i] with vec2[i]
blt next ;if vec1[i] < vec2[i] then branch
inc cont
next: dbne b, loop dec. loop counter + branch if it's !=0

Next example: Write a program to compute the dot product of vectors a + b. Assume the vectors contain unsigned 8-bit values and ignore any carries...

a (dot) b = sum from i to n of a_i*b_i = a1*b1 + a2*b2 + ... a_n*b_n

; Variables
vecA ds.b 5
vecB ds.b 5
result ds.w 1
counter ds.b 1

; Code
ORG $4000
ldx #vecA
ldy #vecB
movb #5, counter
movw #0, result ; We move word because multiplying two bit numbers results in word (???)
loop: ldaa 1,x+
ldab 1,y+
addd result ; Goes into register D
std result ; Put the result stored in D back into result.
dec counter
une loop ; ??

HW # 4
RAMStart $0800
ROMStart $4000

; Initialize SP to $1000

samples ds.b $10,$20,$30,$90
psum ds.b 5

;Screen captures after the 3rd, 4th, 5th addition is completed...
;Generate and submit a list file
;Record 4 flags (N,Z,C,V)
;Determine if an where overflow occurs.
;What is the final sum in decimal?
;Is the final sum a valid signed result?

; Due next Friday (17 Feb 2012)

; Example "stall" loop until bit 2 of 'u' is 0

here: brset u,%00000100, here ; Polling loop...

; Performa bit-wise boolean logic operation between a register r (A,B, CCR) and a memory operand.

; Result saved in the register;
; ... see slides for more info...

If mem. location $10 contains $B3 and register A contains $64, what is the result of the following instruction?

; ANDA $10, ANDA #$40, ORAA $10, ORAA #$10, EOR $10

ANDA $10 ; A 0110 0100
($0010) 1011 0011
0010 0000 (result)

ANDA #$10 ; A 0110 0100
0001 0000
0000 0000 (result)

ORAA $10 ; A 0110 0100
1011 0011
1111 0111 (result)

EORA $10 ; A 0110 0100
1011 0011
1101 0111 (result)

; CCR Logic operations
; Set N + C flags:
ORCC #%00001001

;clear 2+V flags:
ANDCC #%11111001

; Example: Write a loop to toggle LEDs connected to PORTA

ldda #$0
eora #$FF ; =%1111 1111
staa PORTA
;some sort of delay
bra loop


;BSET Set bits in a memory operand by performing ...

bset var1, #%0001111 ; set the lower 4 bits of var1
variable bit "mask"

bclr var1, #11110000 ; clear upper 4 bits

; Logical Shifts
;Left Shift

;Right Shift

; Arithmetic Shift


;Example 7.22 from book
; Write a program to multiply a 16-bit number in D by 10 using arithmetic shift instead of the 'emul' (extended multiply instruction);

temp ds.w 1
std temp
asld ; our value is multiplied by 2x
asld ; our value is multiplied by 2x
addd temp ; Add one more value. Our value is now 5x larger
asld ; D is now 10x

Sunday, October 2, 2011

Microsoft Word to Matlab Matrix Conversion

I type in tons of equations in papers in MS Word (yeah, I need to learn LaTex). So when I have matrices in MS Word, you can't paste into Matlab because the MS Word format is funky. The perlie below will take care of it. Now I need to figure out a way to have it monitor the clipboard and automatically convert it if it detects a MSW matrix:

#echo Part is Microsoft Word Equation:
echo "■(1&0&0@1&-4&2@1&2&-4)"|perl -lne 's/\&/ /g;s/\@/;/g;s/\(/\[/g;s/\)/\]/g;print "A = $1" if m/(\[.+\])/g'

# Matlab Format:
A = [1 0 0;1 -4 2;1 2 -4]
And I decided to make it bidirectional (goes from Matlab to MS Word and vice versa). Pretty awesome...saving me tons of time:
use strict;
use warnings;
print "\n";
my $bit = 0;
my @global;
  if(m/ans =/g){
   $bit = 1;
  if( $bit == 1 && $_ =~ m/\s+((-|\d*)\d+\.*\d*)/g){

sub to_word {
 my $in = shift;
 $in =~ s/\;/\@/g;
 $in =~ s/\s/\&/g;
 $in =~ s/\[/\(/g;
 $in =~ s/\]/\)/g;
 print "[■$1]\n" if( $in =~ m/(\(.+\))/g );
sub to_matlab {
 my $il = shift;
 my @in = split(/■/,$il);
 my @A = ('A' .. 'Z');
  $_ =~ s/\]//g;
  $_ =~ s/\&/ /g;
  $_ =~ s/\@/;/g;
  $_ =~ s/\(/\[/g;
  $_ =~ s/\)/\]/g;
  my $name = "$A[ rand(25) ]$A[ rand(25) ]";
  print "$name = $1\n" if m/(\[.+\])/g;
my $ans = join(';',@global);
$ans = "[$ans]";