Posts Tagged ‘bash’

20090615 Coding nightmares

Upon reading the title, I think I’m right in assuming you probably thought I was going to write about a set of bad practices, or a series of horrible things one could find when refactoring code written by someone else. None of that, this time I’m referring to real, literally speaking, nightmares.

I think it happened for the first time almost 10 years ago. I had to implement a little shell in C for a university assignment and brave me hadn’t a better idea than printing parts of the code from bash and examining it to get an idea of how the real stuff worked. It was all fine and dandy when reading the code at a train (apart from the odd looks that I got from people sitting near me, of course), but it proved to be a very bad idea to keep reading right before going to sleep. That night was the prelude of a long series of bad nights. I spent the whole night dreaming about pointers, structures, functions, loops, assignments, switch statements, case’s, mallocs… you get the point. When I woke up, my brain was totally wasted. It was just like if I hadn’t slept at all.

I thought that had only been a single event and wouldn’t happen again, but boy, wasn’t I wrong! It didn’t happen again, though, until I began to work in web development, and the main cause this time was the Horror. Of course, I’m referring to Internet Explorer Exploder. I have lost count of the number of nights I spent suffering horrible nightmares where things work properly in Firefox and Opera and blah but aren’t properly aligned in IE, or do not show where they should… Anyone who has had to develop for IE will for sure know what I mean.

The easiest way of avoiding these nightmares (for me) is to consciously focus on something completely unrelated before going to sleep. For example, to read something non-technical, like a fiction book where the action preferably happens in a time and place where the most advanced piece of technology is a ball pen.

But over time, there are days where I can’t but get super excited about something code wise, and continue coding right until my eyelids feel so heavy I can hardly keep my eyes open. Those are the nights I go to sleep scared in advance, because I know my brain is totally obsessed with the piece of code I’m working with, and as Bette Davis would say, … it’s going to be a bumpy night! :D

And you? Do you have real coding nightmares? And if you have, how do you avoid them?

20061003 Find out the full referrer (with the shell)

Are you fed up with Google Analytics not showing the full referrer url and just showing something like http://www.example.com/forum/viewtopic.php? I also do, I love to know who’s linking me (yeah I’m curious!).

My hosting compresses access_logs which reach a certain size, so when I downloaded the access logs files I get a bunch of .gz files which I’m not going to manually uncompress… So I went to the terminal and once in the folder where the log files are, I type

find . -name “*.gz” -exec gunzip {} \;

Now I have lots of files like access_log.20060929, access_log.20060930, etc. For searching let’s say a referrer called example.com which I see in GA, I do:

cat * | grep example.com

and that will return you the apache log lines where the term appears.

For example:

81.39.91.97 – - [26/Sep/2006:11:27:47 +0000] “GET /index.php HTTP/1.1″ 200 9562 “http://example.com/viewtopic.php?t=747″ “Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7″

It’s a bit of brute force approach as it’s searching in all the files (now that I realize it’s even searching in the compressed files since I didn’t remove they yet, haha!). But it’s very fast even though!

With a bit more of love this could be a rudimentary stats script but I’m not that much into shell scripting (and I’m trying to force myself into really learning regular expressions to do that stats script with ruby instead).
Oh and I forgot to say this works for any decent shell – linux, mac… I think I also could do it with a windows box with unxutils installed (so that you get the funky stuff like grep, find, cat, etc).