Tar Extract a Single File(s) From a Large Tarball
$ tar -ztvf config.tar.gz
$ tar -zxvf config.tar.gz etc/default/sysstat
$ tar -xvf {tarball.tar} {path/to/file}
Arduino CrossFit Timer – Grizz9000
I was looking for, what I thought, was a simple clock/timer design. Something with a remote and a big display that could be read from across the gym and that I could program with up/down counting but also intervals specific to CrossFit like Fight Gone Bad or tabatas. I wanted to incorporate a bell to give it a gym feel and something that could be heard over loud music.
This journey took me through many designs, chips, a custom board, wood working and a whole lot of learning!
I want to give a special thanks to these sites / companies for all they do.
adafruit.com - sparkfun.com - arduino.cc
“Anyone can sell and anyone can give back but mixing the 2 so others can succeed is tremendous and noble work!“
Here’s a video of the final product:
Let’s break this project into pieces… actually that’s how I approached this. There were many things I didn’t know how to use/do/code before I started. Looking at each piece I would bread board the very simplest design (learn, discover, etc) and then incorporate that into my design; move on.
My first thought was to use the adafruit 16×32 display. This display worked very nicely but I found that I wanted bigger fonts or smaller fonts so I could write more on the one screen. This pushed me to rewrite some code to change fonts. Then I found that my refresh rate was screwing up my IR reads from the remote. As I was reading in a button from the remote, I would refresh and miss the rest of the IR code.
My solution was to use 2 Arduinos! One would be the master refresh and the other the reader for the IR. The slave would bit bang some digital lines and when the master was ready to read it would look and gather up the bits and tell the slave it’s all read. This was a fun challenge as I was burning up digital pins as 4 pins would only give me 16 states (2^4) and I needed some control pins, etc, etc. This actually worked pretty well but I was making things more and more complicated. From here I started to ditch the matrix and move to large LED boards.
Checking online I found some 8″ Large LED displays. Ebay had a pack of 4 for $99 shipped. Sparkfun had a great write up on a wall clock and another one for a BricoClock.
My design quickly changed from the Matrix to LED segments. Issue was common cathode or common anode… no idea! Not to mention that my buying spree had set me up with a bunch of common cathodes and now these large digits were common anodes. After some reading and testing, I found that all this means is that, for common anode (CA), there is one anode pin that all the other pins share. We put +POWER to the common anode and then ground all the others (with resisters, etc, etc) and she’ll light up!
I thought about using the max7219 chip but it needed common cathode (CC) digits and the large ones were CA and that max chip could only handle so much current and I needed to switch the high/low because of the CC LEDs. Now I was onto darlington arrays and UDN2981 and ULN2803 chips
I then tried some SAA1064 4-digit LED display drivers. Tronixstuff did a wonderful tutorial on this. I learned about I2C and all the fun that comes from using those libraries with Arduino.
After all that testing and playing around I needed to start looking at registers and shifting. While there are plenty of great tutorials on shifting (2), none seemed to handle the load of these large LEDs.
I stumbled on a chip called the tpic6a596. Yet another set of numbers and names and this time it was a current SINK chip (which simply means that it just grounds stuff) … my common anode (POWER) leds would hook up to these nicely.
I didn’t find any boards, shields, etc. that would handle this so I figured it was time to design another PCB! In the end, I picked PCB Fab Express for my boards. They turned out great and the price wasn’t too bad. I used the free version of Eagle to design the whole thing. I should say (with my head down) that I did need 1 jumper when the boards came in. The 2 grounds were never connected for some reason. Easy fix though. Another tip is that I printed out the board and taped it on a piece of styrofoam. I then pushed the different components in to see if they fit. This was a HUGE help as many pieces that I ordered were much different than the pkg/layout that I was using on the board.
Here’s a quick video with a 1 chip smoke test
So what about the code? Cmon timing is easy! There are tons and tons of tutorials out there on how to time and even more on how to include RTC chips. I used the adafruit DS1307 for the job. You’ll see in the pics that I even mounted it right on the board instead of having to wire it externally.
I was finding, like most projects, that finishing this thing was going to be the final crux. I needed to find (really build) a box that could be hung up and not look like a DIY project gone wrong. I ordered up some plexiglass from McMaster and another site (forget) and learned that I can’t pick colors worth a damn. I ordered a RED, BLACK and SMOKE. In the end, I used the smoke AFTER I painted the front flat black.
Using a tablesaw that someone gave me years ago and some wood molding, I came up with a BOX. I then ripped a slot for the plexiglass and then carved out the end so the backing would fit. Couple of filler and sanding intervals and it was time to paint.
I’m happy to say that the clock is still running happily at CrossFitGordon. The remote, digits and bell looks and sound great! I’ve gotten some great feedback and proud to have my name on this thing. To date, I need to put a back on the unit, power switch and add a few more fun timers and we should be golden.
Thanks for checking this out and drop me a line in the comments if you have any questions, comments, etc. I’ll be uploading the code as soon as I get it updated with a couple of minor bug fixes.
BTW the name Grizz9000 comes from the owner’s dog “Grizz”!
Also, let me know if you would like to see this CrossFit Timer on something like KickStarter:
Arduino Tutorials
Here’s a great site with PLENTY of Arduino examples and tutorials: Arduino Tutorials « t r o n i x s t u f f.
Vim: How To Fold Functions
The is really a tip on how to fold any code block including functions. Navigate your cursor somewhere inside of the code block you want to fold, make sure you are in command/normal mode (press escape if you need to) then type zfa}
To save your folds between vim sessions you need to issue the command :mkview otherwise when you close vim your folds will be lost (your folds, not your code). To make life easier on you, you can have your folds automatically saved for you by adding this to your .vimrc file
au BufWinLeave * mkview
au BufWinEnter * silent loadview
Source: Refreshingly Blue » Blog Archive » Vim: How To Fold Functions.
Finding Zero Graph Hosts in Cacti
Sometimes when we do all this nice trimming of graphs/etc we trim a host down to having NO graphs at all. these need to be looked at (either remove the host or add some interfaces to be graphed).
Here’s some SQL that will give a list of hosts that don’t have any graphs:
Console Size
Sometimes you just need to work in console … no fancy graphics/etc. Here’s where VGA modes for PC computers comes in. AKA screen resolution
Grab Excel WorkSheet Names Into 1 Sheet
Here’s a nice macro that will combine all your worksheet names into a new sheet.
Some more good excel tips here too plus a cool util called RDBMerge!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | Sub ListSheetNames() Dim NumSheets NumSheets = Sheets.Count Application.DisplayAlerts = False Dim i For i = 1 To NumSheets + 1 If ActiveSheet.Name = "SheetNames" Then Sheets("SheetNames").Select ActiveWindow.SelectedSheets.Delete Exit Sub End If Next i Application.DisplayAlerts = True Sheets.Add ActiveSheet.Name = "SheetNames" Sheets("SheetNames").Move after:=Sheets(NumSheets + 1) 'MsgBox (NumSheets) For i = 1 To NumSheets Range("A" & i) = Sheets(i).Name Next i End Sub |
Project HiJack
Hijacking power and bandwidth from the mobile phone’s audio interface.
Creating a cubic-inch peripheral sensor ecosystem for the mobile phone.
Removing Stale RRD Files
I’ve found that when dealing with rrdfiles, they can show the wrong lastmodified time. This means if I go with the usual: delete all files that haven’t been modified within say 2 days, I could be deleting some GOOD rrd files…
Here’s my solution. Use rrdtool lastupdated to spit out epoch time of last updated and anything that’s older than 2 days we’ll delete:
1 2 3 4 5 6 7 8 9 10 11 12 | for myfile in *.rrd do #rrdtool lastupdate $myfile | tail -1 | awk -F: '{if ($1 < systime()-172800) print strftime("%c",$1)}'; RETURN=`rrdtool lastupdate $myfile | tail -1 | awk -F: '{if ($1 < systime()-172800) print 0}'` if [ "$RETURN" == 0 ]; then echo "Deleting $myfile" # uncomment to really remove file #/bin/rm -f $myfile else echo "Skipping File $myfile" fi done |
Installing Your Own Perl Modules
Sometimes you need to install Perl Modules in your OWN (non root) directory. Found a great writeup on how to do this:
% perl5 Makefile.PL PREFIX=/usr/home/USERNAME/usr/local
% make
% make test
% make install
% make clean
And then in your perl code you would use this near the top:
use lib qw(/usr/home/USERNAME/usr/local/lib/perl5);
There’s another writeup on using CPAN that didn’t work as well for me:
$ mkdir ~/.cpan
$ mkdir ~/.cpan/CPAN
$ cd ~/.cpan/CPAN
$ cp /usr/lib/perl5/5.8.4/CPAN/Config.pm MyConfig.pm
$ perl -pi -e's!/root/\.cpan!$ENV{HOME}/.cpan!' MyConfig.pm
$ perl -pi -e'/makepl_arg/ && s!\]! PREFIX=$ENV{HOME}]!' MyConfig.pm
$ echo "export PERL5LIB=${HOME}/lib/perl5/site_perl/5.8.4/i686-linux:${HOME}/lib/perl5/site_perl/5.8.4" >> ~/.bash_profile
$ . ~/.bash_profile
$ perl -MCPAN -e shell
cpan> install HTML::Template
Wget NASA Photos
Here’s a great wget trick to download all the Photos of the Day from NASA. There’s some great switches in there I never new existed.
wget -r -l2 -t1 -nd -N -np -w2 -A.jpg -erobots=off http://apod.nasa.gov/apod/archivepix.html
(source lifehacker)
Adding Batch Hosts To op5 (Nagios) from CSV
Even with the lovely GUI that op5 comes with, sometimes you need to enter in a large set of hosts into the system. op5 gives you the ability to use the GUI as well as the historical nagios (hosts.cfg) files.
I wanted a way to not only create a hosts file but include some other items as well like the parent of the device, hostgroups and image to use. The input file should be in csv (comma separated format).
So I grabbed some old code on the net that and edited to fit my needs. There are 3 parts
- mk_hosts.sh
- hosts.skel
- inputfile.csv
mk_hosts.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/sh # mk_hosts.sh # convert csv input file into hosts.cfg file=$1 cat $file |while read line; do echo "${line}" NAME=`echo ${line}|cut -d, -f1` ADDRESS=`echo ${line}|cut -d, -f2` IMAGE=`echo ${line}|cut -d, -f3` PARENTS=`echo ${line}|cut -d, -f4` # Since hostgroups may contain spaces let's put at end and grab everything from field 5 on HOSTGROUPS=`echo ${line}|cut -d, -f5- | sed -s 's/"//g'` cat hosts.skel | sed -e "s/TEMP_NAME/$NAME/" -e "s/TEMP_IP/$ADDRESS/" -e "s/TEMP_HOSTGROUPS/$HOSTGROUPS/" -e "s/TEMP_IMG/$IMAGE/" -e "s/TEMP_PARENTS/$PARENTS/" >>hosts.cfg done |
hosts.skel:
1 2 3 4 5 6 7 8 9 10 | define host{ use default-host-template host_name TEMP_NAME alias TEMP_NAME address TEMP_IP hostgroups TEMP_HOSTGROUPS icon_image TEMP_IMG statusmap_image TEMP_IMG parents TEMP_PARENTS } |
inputfile.csv
1 2 3 4 | oracle-prod1,172.2.6.32,redhat.png,ny-router-1,"All Servers, NY DataCenter, Everything, Prod Servers, Linux Servers" oracle-prod2,172.2.6.33,redhat.png,ny-router-1,"All Servers, NY DataCenter, Everything, Prod Servers, Linux Servers" oracle-prod3,172.2.6.34,redhat.png,ny-router-1,"All Servers, NY DataCenter, Everything, Prod Servers, Linux Servers" win-exchange,172.4.6.32,windows.png,ny-router-1,"All Servers, NY DataCenter, Everything, Prod Servers, Window Servers" |
Your CSV file should use the following columns:
Name, IP, Image_Name, Parent_Name, HostGroup(s)
Once you have done this simply run the command (outside of your etc dir):
1 | ./mk_hosts.sh inputfile.csv |
Now look at the newly created file hosts.cfg
If everything looks good, simply cat >> this onto the end of the hosts.cfg file. Within op5, goto config and it will notice you have a NEWER config. Click save and all is well. If not, go back and fix the errors.
BTW: You might want to create a backup within op5 before doing this just in case you lay down some wrong hosts.





