-
Moving Shop
For a couple of reasons, I’ve decided to create my own blog and host it on Heroku. From now on, that’s where Coded World will live. Thanks!
Posted on March 14, 2012 with 1 note ()
-
Interactive Flowcharts with TikZ
While writing my thesis I realized I need a couple flow charts to help clarify the flow of steps used in my model. I first reached to PowerPoint like I have in the past, but in a lapse of brilliance I did a google search for flowcharts in latex and came across TikZ and PDF. These two packages work together to let you programmatically create graphics in LaTeX. It took me a minute of digging through the examples to understand the syntax and get a working flow chart, but the way I see it, it’s better to invest the time up front learning a new tool knowing that in the long-run it’ll save you time.
For me there were two big reasons I wanted to do it this way. First, I wanted to have a vector graphics flow chart and PowerPoint doesn’t let me do that. Second, I like being able to maintain/edit my flow chart without having to open up a separate program. These two reasons are good enough, but I had another stroke of genius a couple days back and made my flow chart better than anything PowerPoint could ever do.
I realized that since my flowchart bubbles are representative of sections in my thesis, I could use the \ref (or I prefer \cref) and now my flow chart has a link within it to the section. It’s beautiful!

Unfortunately, since my thesis isn’t finished yet I can’t put up the source (or let you see the entire flow chart). If you’re having trouble with TikZ, hit me up on twitter and I’d be happy to help.
-
Auto-website checker thingamajig

I bet you didn’t know that’s how you spell “thingamajig”. It is.
Anyways, I just submitted my first first-author paper yesterday and I’m obviously now obsessed with checking the status page, but why check it manually when I could make a computer check it for me? With the power of nokogiri to parse the html and the whenever gem to make dealing with cron less of a headache, I can make this happen. After trying things out in irb, I figured out a way to get the status of my submission from the page. Now that I have a way to getting the information, I just needed a script that could pull the status, compare it to what it got last time it checked and send me an e-mail if it changed. I was a little nervous that sending an e-mail was going to be a hassel without using Rail’s Action Mailer, but like most things in ruby, there’s a gem for that. The pony gem makes sending mail with the *nix sendmail utility a piece of cake.
I had the tools, so all I had to do was wrap everything up in a simple script and use the whenever gem to run it every 30 minutes. I put the code up on my github (https://github.com/greggroth/CheckWeb), so check it out. Do you know of a better way to monitor changed on a website?
Posted on February 8, 2012 with 1 note ()
-
Cleaning house: Using ‘du’ with ‘awk’
If you use Dropbox as much as I do, then you’re familiar with filling it up. While there are applications available to help you figure out what’s taking up space in a folder, I prefer to use a simpler approach. The ‘du’ command gives a report of the disk usage of all the files for each subdirectory in a folder. While it’s useful on it’s own, it gives such a large output that it can be a bit difficult to wade through. Thankfully, we can route the output of ‘du’ to ‘awk’ and use that to pick out the information we’re really interested in. For example, to find files that are larger than 100 MB, you can run (within your dropbox folder):
du -m | awk ‘$1 >100’
The -m flag on du tells it to printout the size in megabytes. This gives a much more concise list and makes it much easier to find the main offenders. I found the files I don’t need anymore, removed them and now my Dropbox is ready to go. Do you have a method you prefer to use to clean house?
EDIT: I came across another way of approaching this using the ‘find’ command:
find . -size +100M
gives a list of files that have a size over 100 MB, but this output doesn’t include the file size. With a little bit of awk code, this could be fixed using the ‘ls -s’ command, but I’ll leave that to the reader. :-)
-
Thesis time means LaTeX time.
I’m in the last semester of my masters program (physics) which means it’s time to put everything into a thesis. Like many others who are embarking on writing any document that includes >0 equations or tables, using MS Word is not an option. For that reason, I’ve become very acquainted with and am now a huge fan of LaTeX.
It does have a bit of a learning curve, but once you get a hang for it, using LaTeX makes things so much easier to handle. Rather than typing out “Introduction” then changing the font/size to match what you think you want for your chapter headings, LaTeX lets your just type “\chapter{\label{ch:intro}Introduction}”. This may look more confusing, but once you see past all the slashes and curly braces, it’s beautiful. All I’ve done is tell LaTeX that I want a chapter to start here and for it to have the heading “Introduction”. The secret bit I snuck in there is another thing that makes LaTeX amazing — \label{}. By labeling the chapter, if I need to refer to it in a different part of the document, all I have to do it type “\ref{ch:into}” and it fills that in with the number. This means I don’t have to manually go through and make sure I didn’t mess anything up by adding in the last-minute chapter or section. LaTeX takes care of it all for me.
If you need to write any kind of long document (especially technical documents), I highly recommend you trying using LaTeX (introductory guide to get you started). Once you get started and have learned the amazingness that is BibTeX to do your citations, I have a bash script which will come in handy (https://gist.github.com/1672399). This will automate the process of running “latex, bibtex, latex, latex” every time you want to build your document. It’s a huge time saver for me.
-
h5utils, libpng and OSX Lion
I spent most of Friday and Monday trying to trouble shoot an issue compiling h5utils on my MacBook Pro running OSX Lion (10.7.2). I kept getting an error in the writepng.c function (full message) and I couldn’t figure out how to solve the issue. Thankfully, I got lucky and stumbled on someone’s gist with a homebrew formula for installing these tools under OSX Lion. It turns out the issue is between libpng (1.5.7) and Lion and not with h5utils. Since I had such a hard time finding the solution, I wanted to post about it in hopes that I might be able to save someone else a few minutes. Here’s the formula I found (link):
require 'formula'class H5utils < Formulaurl 'http://ab-initio.mit.edu/h5utils/h5utils-1.12.1.tar.gz'homepage 'http://ab-initio.mit.edu/wiki/index.php/H5utils'md5 '46a6869fee6e6bf87fbba9ab8a99930e'depends_on 'hdf5'def installENV.x11 # enable libpng support# patch for libpng 1.5 as described by https://github.com/mxcl/homebrew/pull/6944inreplace 'writepng.c', 'png_ptr->jmpbuf', 'png_jmpbuf (png_ptr)'inreplace 'writepng.c', 'free(info_ptr->palette);', '/* free(info_ptr->palette); */'system "./configure", "--disable-debug", "--disable-dependency-tracking","--prefix=#{prefix}"system "make install"endendPosted on January 17, 2012 with 1 note ()
-
git-guide
I love git and now use it religiously to add versioning to my programs and even some documents. It’s really good at letting you keep track of changes and merging changes made by different users or by you in different branches. Used in conjunction with a remote repository (i.e. github) it provides a great backup tool for your code. If you haven’t used it before, check out this beginner-level guide.
-
Neat Terminal Commands
In the past year, I’ve been using the terminal (recently started using zshell which I recommend checking out if you haven’t heard of it) a lot more and along the way I’ve found a couple commands which I wish someone had told me about sooner.
cat [filename]
This command concatenate’s the contents of a text file. This is perfect for when you need to quickly check a file, but don’t want to open it up in an text editor like vim or TextMate
locate [query]
I use OSX’s spotlight utility a lot to quickly open up applications or find files, so when I started using the terminal more I quickly wanted a way to search my disk for files. Thankfully, people smarter than me already made it a part of bash. You pass it a query and it outputs a list of full path results. Perfect for searching your entire drive, but sometimes you just want to find something within the current directory (and it’s subfolders). For that, we go to my next favorite
find [path] -iname “[filename]”
find [path] -type “[filetype]”
Example: find . -iname “abc*” will return a list of files in the current directory (including subdirectories) who’s name start with “abc” (case-insensitive and the asterisk is a wildcard character which simply means the rest of the filename doesn’t matter). This is one of the those functions that are really powerful, but have so many options that it can be a bit intimidating to learn. The two cases above are the way I use it most of the time.
grep [query] [filename]
The last of the useful searching utilities is grep. This is used to search for a string within a file.
bc
I just came across this one recently — it turns out bash as it’s own calculator built it. It’s only good for simple math and for that I usually use either use Ruby’s irb or Wolfram Alpha, but it’s good to be aware of it just in case. One helpful hint to save some googling later: to change the displayed precision, use the command scale=x where x is the number of digits you want visible after the decimal.
echo “Hello, Bob!” | sed ‘s/Bob/Gregg/’
Ok, so this particular example isn’t very useful, but it demonstrates both the pipe ( | ) and the sed function which can both be pretty neat. The above example will output “Hello, Gregg!”. The pipe takes the output from echo and passes it to sed. sed then replaces the first instance of “Bob” with “Gregg”. Your imagination is the limit with what you can do with this one.
cal
Strictly a ‘neat’ utility that displays a formatted calendar. It’s good if you need to check a day of the week or something.
So that’s it. It’s a short list of some bash utilities that help me do my thing. Here’s a site which goes through some other nifty tips and tricks. Have any lesser-known utilities I missed that you find indispensable?
Posted on January 6, 2012 with 1 note ()
-
Should I use a penny instead of a fuse?
Short answer: no. But this is probably not a surprise. If you’re unfamiliar with home repair or electronics, a fuse is a part of a circuit designed to fail if the current flowing through the circuit becomes too large. It’s there so that it fails before that nice HDTV receives a lethal current. There isn’t much to a fuse: it’s a thin wire that melts when too much current flows through it. The reason it melts boils down to energy that’s lost by electrons as they move through a material. A guy named Joule came up with a relationship for exactly how much heat is lost:

Where Q is heat, I is current, R is electrical resistance and t is time. So, how much current can a penny withstand before melting?
To start off, we need to know how much heat it takes to melt a penny. The melting point of copper is about 1350 K and the latent heat of melting of copper is about 176 J/g. With a copper penny (about 3 g) that gives a total heat of about 2100 Joules to melt (using 0.385 J/g k as the specific heat). Next we need to know what the resistance of a copper penny is.
The diameter of a penny is just under 2 cm, so I’ll use 1.5 cm to allow for the contacts. I’m going to be lazy and just call it a cuboid that’s 1 mm tall. Using the equation for resistance, I get about 0.00002 Ohms. This is an extremely low resistance, so there wont be very much energy lost to heat. Rearranging Joule’s law to solve for current and substitution our values in (assuming you want it to fail within 0.1 s), it’ll take over 32,000 Amps of current. Most fuses at your house will be rated to fail at either 40 or 60 amps, so this is a HUGE amount of current that would be allowed to flow.
Long story short — don’t use a penny.
EDIT: I know that the current penny isn’t really copper any more (it’s ~98% zinc), but even if you use values for zinc, you come out with about 13,800 amps. Still a lot of current and also on the low side because of the remaining 2.5% copper (it’s also important to note where the copper is since charges in a conductor flow on the surface and not through the center!). So composition aside, don’t use a penny. Just don’t.
Posted on May 31, 2011 with 2 notes ()
-
Möbius ship, based on the Möbius strip, a surface with only one side.
Posted on May 29, 2011 via matthen with 138 notes ()
