Entries from October 2006

Tuesday, October 24th, 2006

Perl One Liner – Search Replace String in File

This is one of the most useful perl one-liners. Search and Replace a string in a text file.

perl -0777 -i -pe 's/patterntomatch/replacewith/g' inputfile

Let's break this down
-0777: treat file as a single line, this way we don't have to worry about ranges on our regex.
-i: operate on file in place. super dangerous and fun. If [...]

Monday, October 16th, 2006

Derived Columns in ActiveRecord

Sometimes it's useful to have a field in your ActiveRecord implentation that isn't actually selected in your query or present in your table. One way to acheive this is by simply adding a new accessor to your Model class.
Let's say we have a table named Customers that has a firstname and lastname column but we [...]

Monday, October 9th, 2006

Formatting Numbers in Oracle and Postgres

When dealing with large numbers in oracle sometimes it can be hard to read the results from a query with no formatting in the results. I know I have misread numbers from a query many times. Well, I finally got around to looking up how to format numbers in oracle. And who knew -- TO_CHAR [...]

Friday, October 6th, 2006

Randomizing an array in Ruby

Ruby's Array class has no method to randomize the contents of an array. Of course, Array can easily be extended to include this functionality. And like anything else in Ruby, there's more than one way to do it. Here's one way:

class Array
  def randomize
    arr=self.dup
    self.collect { arr.slice!(rand(arr.length)) }
  end
  [...]

Friday, October 6th, 2006

Defeating Firewalls with Putty and SSH

Once in a while we all get stuck behind a firewall and just have to get around it. You could use one of the many anonymizer web browsing sites which is most likely blocked or use some random proxy in Eastern Europe that features a totally leet 476 ms ping. Or if you have an [...]

Friday, October 6th, 2006

Creating comma delimited lists with vim

Sometimes you just want a comma delimited list. But all life has handed you is a newline delimited list. Lucky for us, God made vim.
Bookmark to:

Friday, October 6th, 2006

Here We Are Now, Entertain Us!

public class HereWeAreNowEntertainUs{
public static void main(String[] args) {
System.out.println("Here we are now, entertain us!");
}
}

Bookmark to: