Pedro Assunção

Archive for November, 2011

Count (group by) number of line occurrences in file

Here’s a neat ruby script to group and count the number of occurrences of lines inside a given file. count.rb list = IO.readlines(ARGV[0]) h = Hash.new {|hash, key| hash[key] = 0} list.each {|item| h[item] += 1} h = h.sort_by { |k,v| v }.reverse h.each_with_index do |p,i| puts “(#{p[1]}) #{p[0]}” if ARGV[1] and ARGV[1].to_i <= i [...]

Red Hot Chili Peppers lyrics generator

Here’s a little something i tried yesterday: a ruby script that mixes and matches verbs, nouns, adjectives, and colors to come up with crazy ass lyrics, red hot style. Enjoy $nouns = IO.readlines(‘names.txt’) $adjectives = IO.readlines(‘adjectives.txt’) $verbs = IO.readlines(‘verbs.txt’) $adjectives << ['red','blue','green','white','black','yellow','brown','gray'] $pronouns = IO.readlines(‘pronouns.txt’) $adverbs = IO.readlines(‘adverbs.txt’) $prepositions = IO.readlines(‘prepositions.txt’) def get_rand(collection) sleep rand [...]

HTML WYSIWYG editor with Flickr upload support?

Lately i’ve been tinkering around with the idea of recreating my blog in a more handcrafted way (ruby on rails) as opposed to the current implementation using WordPress. Don’t get me wrong WordPress is awesome. It has many years and millions of websites as a testament of it’s awesomeness behind it. But i guess my [...]

Self physiotherapy

This is what my evenings look like now: moving my arm slowly, trying to recover wrist movement. It’s unbelievable what one month of no mobility will do to your tendons and muscles. Hopefully next week I can start proper (professional) physiotherapy and do it faster.