Rubyists Have More Fun: Drug Themed Ruby Gems

Posted in Programming, Technology on December 15th, 2011 by Carl Zulauf

I recently noticed we are using at least two “drug themed” gems in our current Ruby project. In my previous adventures in PHP, Java, and other languages I never ran into any drug themed libraries, so I found this curious, and a bit fun. I thought I’d take a few minutes and see how many Ruby gem authors have had some fun with their gem names by searching through gems for other drug themed gems. Here is the list I came up with:

  • valium – A gem that lets you get around the ActiveRecord instantiation penalty while retaining the awesome power of using ActiveRecord.
  • crack – A simple XML/JSON parsing library.
  • joint – Provides GridFS functionality to MongoMapper… seems kind of like a simple paperclip+fog implementation for MongoMapper.
  • cannabis – Simple permissions gem.
  • psychedelic – A very “psychedelic”, maybe even just “psycho”, syntax colorizer.
  • cocaine – A gem which provides a bunch of functionality for executing system commands.

Can you guess which two we’re using?

I don’t know if these gems are a positive or negative for the Ruby community. Personally, I like that the ruby community has such a great sense of humor. There are other humorously named gems out there that have nothing to do with drugs, like polyamorous and bourbon. I think it’s fantastic the Ruby community seems to remain constantly aware of the fact that programming should be fun, artistic, and expressive. My initial reaction is that these “funny” gems are just a symptom of that awareness; behavior that is generally embraced by the community.

What do you think? Are these gems good or bad for the community? Any other drug themed or humorously named gems I missed? What about libraries from other languages?

Advanced ‘grep’: Search for Multiple Strings Simultaneously

Posted in Programming on December 14th, 2010 by Carl Zulauf

It took me a while to figure out how to do this so I thought I’d post a quick guide for other people who might need to have this trick up their sleeve.

The unix/linux grep command can use POSIX extended regular expressions. I learned from this guide that unlike most other regular expression implementations the meta-characters must be escaped to be treated as meta-characters. If they are not escaped grep will treat them as literal characters. This is exactly opposite of most regular expression engines where you escape meta-characters when you don’t want them treated by the regex engine as special characters.

I’m not particularly great at regex and I didn’t find a lot of guides on using extended POSIX regular expressions with grep. This really surprised me.

In my scenario I had a really large file I needed to search through. I had several unique strings I thought might be in this file and due to its size I didn’t want to execute a separate grep command for each string. This would be woefully inefficient as the entire file would be searched independently for each string. This approach would also take much much longer to complete and would be a lot more work for me.

Instead, I knew there had to be a way to craft a single command that would search the file once looking for any lines containing any of the strings I supplied. Well, using my mediocre knowledge of regular expressions and my new-found understanding of the behavior of grep’s regex engine I came up with the following command:

grep -nE \(string1\|string2\|string3\|string4\) theFile.txt

Breaking down the command further:

  • grep – Indicates we are using the unix/linux grep utility.
  • -nE – These are the grep “options.” ‘n’ tells grep to tell us which line number any matches came from when it spits out its results. ‘E’ tells grep to use its extended regular expression engine (required for this kind of search).
  • \( and \) – These are the “range” boundaries for the regular expression. Technically not required here, but I find it good practice to use ranges in case you ever need to back reference. Grep would treat these like any other string if they weren’t escaped with the backslash. We want grep to treat these as special regex characters (range boundaries in this case) so we must escape them.
  • \| – The regex “OR” operator. This tells grep that it can match either the value to the left or the value to the right of this operator. If you read out the statement above as “or” the command makes perfect sense. We are telling grep: find string1 OR string2 OR string3 OR string4 in theFile.txt. Since we want this to be treated by grep as an OR operator and not just another character it also needs to be escaped with a backslash.
  • string1, string2, string3, and string4 – The strings grep should be looking for in the file. The line “I like the taste of string1′s bread” would match string1 and would be in the results outputted by grep. The line “I think String2 has a really mean demeanor” would not match since this search is case sensitive by default.
Tags: , , ,

PDF Ruby Books for Free

Posted in Programming, Technology on April 9th, 2010 by Carl Zulauf

Many of us carry a device or two around with us capable of reading PDF files and there are often times when a reliable connection to the internet is not available. Whether it be a laptop you’re working on or a companion device like a smart phone (Palm Pre, iPhone, Android, etc.) or something like the iPad or Kindle there are cases where you might want a programming resource for one of these devices which doesn’t depend on an internet connection. Also important to many of us is price. There are several great books related to Ruby programming, but few of them are free and even fewer available as a free PDF download. Below are direct links to some free PDF Ruby books.

I am looking at solutions for cleanly converting the RDoc documentation for ruby core, Rails, and a variety of gems. I will update this post or make a new post if I figure that out.

Tags: , , , , , , ,

Printing a Specific Line From a Large File in Linux

Posted in Programming on December 4th, 2009 by Carl Zulauf

I recently had to find a specific line in a large (28GB) file equipped with nothing more than the line number. I thought it would take me just a few seconds to find a cool *nix utility to accomplish this task. Instead, it took me a bit of scouring to find something that works, and works well on large files. That’s OK though since I had to wait for the 28GB file to uncompress from a tarball… which, obviously, takes a while.

What I learned about while I waited was the *nix command ‘sed’. This is a tool built for command line processing of data files. Apparently it was birthed as an evolution of our trusty friend ‘grep’. The forum post I found which hinted that ‘sed’ was my solution didn’t provide much real information and the Wikipedia article was mostly background and provided examples that won’t help me.

Where I found the most useful info was the sed page on sourceforge… go figure. The docs page pointed me to ‘The sed one-liners‘ by Eric Pement. Here I found, through example, the power of ‘sed’ and an example that is more efficient on large files than the ones I found elsewhere.

So here is how you do it:

sed '34005050q;d' filename

’34005050′ is the line number. ‘q’ tells sed you are looking for that line number, and ‘;d’ tells it to stop after that line. ‘filename’ is of course the file you are trying to coax a specific line out of. To do an inclusive range of lines all at once (lines 8 through 12, for example), do this:

sed '8,12!d' filename

I’m still learning about ‘sed’ but its already saving my ass. Have fun.

Tags: , , ,

ExaNotes – An Overdue Introduction

Posted in Programming, Technology on June 17th, 2009 by Carl Zulauf

Several months ago I started working on ExaNotes as a lightweight personal tool to write, access, and search notes from one of the many computers I may use throughout the day. I told a good friend of mine about the simple web app I was building and she said it sounded like a great tool for keeping a journal. I asked her if she could help test the app by keeping a journal and she hesitated. As good of friends as we were the idea of me having access to her journal was not a comfortable one. The convenience of being able to access her journal from any computer was appealing but she didn’t want to trade control of her privacy for convenience. Her desire for privacy gave me the idea of developing a system that was so secure that even the developer or administrator of the tool could not access the content users of the application have stored within it.

I decided to use this as a chance to learn much more about building secure web applications and I spent a few hours diagramming the concept. Then, I spoke with my friend again. I explained the design to her and she agreed the design would keep her journal secure enough that she would feel comfortable testing it and using it. Read more »

Tags: , , ,

Greasemonkey Script: ArsTechnica Cleaner

Posted in Programming on December 4th, 2008 by Carl Zulauf

This is another fairly simple Greasemonkey script I’ve made to make viewing ArsTechnica much easier. This script hides, removes, and reorganizes superfluous content, widens the main content pain a little, and removes all flash. This is extremely helpful when you are reading many articles at a time and don’t want the flash animations on every article slowing down your computer. Scrolling smoothness, tab switching, and general responsiveness of your browser will be improved, especially on older/slower computers. Also, I find the slightly wider content pain to be easier to read.

Like last time, this script is also available through userscripts.org.

Tags: , ,

Twitter Refresher Script for Greasemonkey/Others

Posted in Programming on September 11th, 2008 by Carl Zulauf

I wrote my first Greasemonkey script today, and it happens to be an automatic Twitter Refresher. The script will refresh Twitter every n seconds (10 seconds by default), unless you have placed any input in the input field, in which case it will not refresh.

I haven’t tested this in Greasemetal (Google Chrome) or Greasekit (Safari) yet, but it uses very simple and standard javascript DOM to work, so I’m pretty sure it will work fine in other userscript environments.

Pretty simple, but its something I really wanted so I figured I would share in case anyone else needs a tool like this. Also available through userscripts.org.

Let me know if you can think of any other sites this would be useful for.

Tags: , , , , , ,

PHP: Is Output Buffering Significantly Slower Than Strings?

Posted in Programming on August 8th, 2008 by Carl Zulauf

I love PHP. I use it constantly for rapid prototyping and small scripts that help “glue” things together for me. However, one annoyance I have with PHP is related to building large strings. This isn’t particularly difficult in PHP… in fact its easier in PHP than most languages. The problem is that sometimes my entire page output will need to be contained in a string for various reasons (headers still need to be sent, the output needs to be passed to a filter or other function, etc…). Creating multi-line strings in PHP using single or double quotes looks awful, and the heredoc syntax prevents proper indentation. All of these methods also require tons of concatenation if any logic is necessary. Sometimes I have forgone these methods and instead used Output Buffering to prevent output from being sent, then I simply grab the content of the output buffer and store it in a string. This has several advantages, including ease of coding and the freedom of using the same code whether I need the output stored in a string or sent to the client immediately. However, its main disadvantage is that it is much slower… right? Well, I decided to find out exactly how much slower Output Buffering really is. Read on for my results.
Read more »

Tags: ,