Posts for Tag: findings

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 / 10000 collection[rand * collection.length.to_i - 1] end

def preposition_phrase "#{get_rand($prepositions).strip} the #{get_rand($nouns).strip}" end

def adjectivated_subject_phrase the_part = "the" if rand.to_f > 0.5 adjective = get_rand($adjectives).strip if rand.to_f > 0.5 return "#{the_part} #{adjective} #{get_rand($nouns).strip}" if the_part and adjective nil end

def generate_phrase as = adjectivated_subject_phrase adjectivated_subject_part = as.nil? ? get_rand($pronouns).strip : as preposition_part = rand.to_f > 0.5 ? preposition_phrase : "" verb_part = get_rand($verbs).strip object_part = rand.to_f > 0.25 ? get_rand($nouns).strip : "" the_part = (rand.to_f > 0.5 and object_part != "") ? "the" : "" adverb_part = rand.to_f > 0.75 ? get_rand($adverbs).strip : ""

"#{adjectivated_subject_part} #{preposition_part} #{verb_part} #{the_part} #{object_part} #{adverb_part}".squeeze(" ").strip end

def generate_lyrics result = "" (1..5).each do first_phrase = generate_phrase new_phrase = generate_phrase while new_phrase[-2, 2] != first_phrase[-2, 2] or new_phrase.split(" ")[-1] == first_phrase.split(" ")[-1] do new_phrase = generate_phrase end result << "#{first_phrase}\r\n#{new_phrase}\r\n\r\n" end result end

puts generate_lyrics Here are the sources: rhcp_lyrics_v2.tar. As a bonus there is a script to see how many attempts are required to reach the phrase "The quick brown fox" :)

Arm broken equals free time

I have broken an arm. This is the 1st time in my life that I have broken any bones in my body. And it sucks!

But, rather than being all pessimistic about it, I prefer to see the positive side. See, you get a lot of free time to do things that you probably have been postponing for ages. For instance, taking care of your taxes, organizing all the receipts of last year's expenses, or even turning an old laptop into a hallway digital information system (yes, with one arm). These are the kind of things that I would definitely be dragging on for years before I finally came around to doing them.

Another good side of this situation is the fact that you learn how to be more resourceful because, obviously with only one available arm, trivial everyday tasks become rather challenging. To give you an example I bet that you have never tried to put on socks or open bottles with only one hand. This actually gave me an interesting idea which is to write a couple of posts about easier ways to perform some of these tasks. But that's something for another occasion.

The same good side about breaking a bone, time, is also in itself really crappy. I cannot wait to go skydiving again so, naturally, I had to ask my doctor whether there was a way I could speed up the healing process. Maybe with some kind of calcium and/or vitamin supplements, I thought, my body would be good to go in a month. Of course the doctor, after laughing in my face, proceeded to explain that there isn't really anything you can do but wait. The tissue regeneration takes about 3 weeks. Because, when you break a bone, you also do a lot of damage to the surrounding flesh, tendons, and muscles. The bone itself takes about 5 weeks to reach a state of good calcification. Finally, when you get the cast taken off, you have to do a bit of physiotherapy to get back the amplitude of movement on the joint(s) that have been on cast. The bone calcification will continue on for one or 2 months, after which it will be so much stronger that you will never break it in that same place again.

The bottom line is my doctor has now become my newest skydiving instructor: I will only be allowed to go up when he says so :-)

Export Mysql result as CSV

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 :)