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 [...]
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 [...]
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 [...]
Don’t ask me how the sed magic works, but it does. Taken from here. Running this: mysql -u<USER> -p<PASSWORD> <DATABASE> -B -e “select * from videos_video;” | sed ‘s/\t/”,”/g;s/^/”/;s/$/”/;s/\n//g’ will produce something like this: “id”,”title”,”url” “1″,”video 1″,”http://youtube(…)” “2″,”video 2″,”http://youtube(…)” “3″,”video 3″,”http://youtube(…)” Just pipe it to a .csv file and you’re done
If you are developing in Swing and using hibernate you might – at some point in time – run into this exception: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session What happened, you might ask? Well, turns out that when you close the session that created a given [...]
Here’s a little script to get the latest earthquakes worldwide (1 hour). Sorry, Ruby purists, for not using RSS 2.0 and hpricot for a cleaner extraction of the coordinates, but my xcode installation is messed up and i can’t build any gems require ‘rss/1.0′ require ’rss/2.0′ require ‘rss/atom’ require ‘open-uri’ require ‘cgi’ source = “http://earthquake.usgs.gov/earthquakes/catalogs/1hour-M1.xml” # [...]
Application markets and stores are all the rage these days. Let’s see, there’s the apple store, the android market, Microsoft’s app store, Nokia’s OVI store, and probably a gazillion more. It’s like if you don’t have one, you don’t really exist. Well, now the eclipse IDE has got one as well. You can get plugins [...]
As a part of my Ruby learning process, i decided to write something to retrieve the full list of brands that Coca Cola currently owns from their website. The list is split across multiple pages, but with some Ruby magic and a nice library called Hpricot to traverse the HTML it was 5 minutes of [...]
One of the biggest pains of any developer is maintaing the source code. Especially if you – like me – have a gazillion pet projects that need to be updated whenever you come up with “cool idea #20000″ for one of them. Version control systems like Mercurial are awesome, but they are only part of [...]
After reading a post in PCPro.co.uk, about the dual core ARM phone that can run both Android and Ubuntu at the same time, i can’t help being excited about the possibilities that the near future holds for us, mobile-wise. I’m pretty sure that – at some point in time – we will not need laptops [...]
Just some notes i might update while going through the procedure. To start with, gem might complain that bundler requires a higher version. Something like this might happen, when you run “sudo gem install rails”: ERROR: Error installing bundler: bundler requires RubyGems version >= 1.3.6 ERROR: Error installing bundler: bundler requires RubyGems version [...]
Recently i had to fill one of those client/customer satisfaction surveys. Endless pages of “how well do you grade feature X” questions that frustrate you beyond the point of killing yourself and your colleagues. And that got me thinking: how about a simple form that asks “Are you happy? Yes/No”? If you answer “yes”, case [...]
So here’s something you can’t find on the internets. Or at least i couldn’t, when i was trying to find a way to do this. The problem: Traditionally, spring and hibernate have been mostly used in web applications. In this case, you can easily define your domain objects to have lazy collections because spring/hibernate will [...]
One of my current projects requires me to deliver a Swing application via Java Web Start. This meant some research to figure out how that works. Since i’m a nice guy, here’s the result for everyone that needs it. As you can see – in the folder structure image – there are some files that [...]
Today i found a neat trick. Typically when you inject an AnnotationSessionFactoryBean into one of your classes you end up with a SessionFactory on the other side. This is because Spring is doing its magic inside, proxying stuff so you end up with an easy way to instantiate hibernate sessions. The problem is that i [...]
It recently came to my attention the existence of this heavily-client-based web framework to develop desktop-like applications called Sproutcore and is backed up by Apple (there is another cool alternative called Capuccino). Basically it relies on Javascript to create nice desktop-like applications, but on the web. Ever since i heard about node.js i have been [...]
Today at lunch i felt taken by this concept once again. A long time ago it came to me that software, au contraire of living beings, does not evolve; the best description for it, in my not-so-humble opinion, is of a big tower of LEGOs building blocks: You start stacking them up and, when a [...]
After an awesome Japanese dinner with my good friend Luizzz , we came to the conclusion that the website that was missing was one where you could bomb any country in the world. … So over the course of about 8 hours – the next day – we came up with bombthiscountry.com , a meaningless website where you can bomb any country in the world (yes, China, Tibet is a country).
I recently came across an article entitled “Pair programming works“. To be honest, the first thing that crossed my mind was that this would be a cartoon mocking the concept. Fortunately, i was wrong as the article gives very compelling arguments on why “Pair programming” has a lot of benefits, both to the employer as [...]