Ramblings Of a Madman

Yeah, like i would know a good description…

Posts for Tag: experiments

SecuritySpy Control

Yesterday i made my first attempt at selling an Android application on the Play Store. Knowing both the Apple Store and the Play Store, i can't help thinking that the latter was a much more pleasant experience than Apple's. Maybe because of the underlying web technology, or the fact that the pages loaded faster, or simply because the number of steps was lower and their explanation was much more trivial, i have to admit that i prefer Google's experience.

In any case, this is purely from a merchant developer's perspective, it has nothing to do with the stores' experiences to the customers. In that regard both Apple and Google did a fantastic job. Google even went the extra mile allowing you to purchase stuff on the web store and "telling" your device to install it automagically. I, for one, love that feature.

That's it. This was mostly a comparison post and, at the same time, an experiment for my new multisite blog installation with both English and my native language, Portuguese. If you click the flag on the left sidebar you should be transported to the same post in a different language. Fingers crossed ;)

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

New blog layout

It was bound to happen; I get easily bored with website layouts and i saw that cluttered old design going away for some time now.

This new theme, a much more clean version, is an adaptation of Fiver, by Stinkyinkshop. I think it works really well, wouldn't you say? :)

Full list of Coca Cola brands - had no idea there were so many

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

Here's the script: require 'open-uri' require 'rubygems' require 'hpricot' require 'pp'

my_file = File.new("cola.txt", 'w')

('a'..'z').each do |letter| open("http://www.thecoca-colacompany.com/brands/product_list_#{letter}.html") do |f|

# meta info #pp f.meta

#pp 'Content-Type: ' + f.content_type #pp 'Last modified: ' + f.last_modified.to_s

doc = Hpricot.XML(f) div = doc/"#products_link_list" (div/:ul).each do |ul| (ul/:li).each do |li| if (li/:a).first my_file.puts((li/:a).first.inner_html) else my_file.puts li.inner_html.to_s end end end

end end And here's the full list of brands that belong to Coca Cola:

A&W Acueducto Ades Agua Manantial Ali Alive Alpina Ambasa Ameyal Amorino Andina/Andina light Andina Fortified Andina Fresh Andina Frut Andina Nectar Apollinaris Aqua+ Aquabona Aquactivede by Aquarius Aquana Aquarius Aquarius Active Diet BACARDI Mixers* BACARDI Premium Mixers* Bajoru Gira Bankia Barq's Barrelitos BEAT Beautia Bebere Benedictino Beverly Bevi Bibo Big Crush Big Tai Bimbo Bimbo Break Biotime Bird's Nest* Bistra Bistrone Bjare Blackfire Boco Bogadera Bom Bit Maesil BonAqua/BonAqa Borneo Botaniq 1QQ Botany BPM Brazzi Bright & Early Brisa Agua Pura Brisa by Bonaqua Brisa con un Toque de Gas Brisa Spa Bu Bubbly burn buzz CAFÉ ZU caffeine-free Barq's caffeine-free Coca-Cola caffeine-free Diet Coke/caffeine-free Coca-Cola light Calypso Canada Dry Canning's Cappy Caprice Caribou Coffee* Carioca Cascal Carver's Cepita Chaqwa Charrua Chaudfontaine Cheers cherry Coke cherry Coke zero Chinotto Chinotto light Ciel CITRA Club Coca-Cola Coca-Cola Black Cherry Vanilla Coca-Cola Blāk Coca-Cola C2 Coca-Cola Citra Coca-Cola light/Diet Coke Coca-Cola with Lemon Coca-Cola with Lime Coca-Cola with Raspberry Coca-Cola Zero Cocoteen Cola Guaraná Jesus Country Club Cresta Cristal Crush Crusta Crystal Damla Minera DANNON* DASANI DASANI Active DASANI Balance DASANI Flavors DASANI Nutriwater DASANI Plus Del Valle Del Valle Frut Del Valle Frutsi Del Valle Frutsi Desarrollo Del Valle Kapo Del Valle Mais light Del Valle light Delaware Punch diet A&W diet Andina Frut/Andina Frut light diet Andina Nectar/Andina Nectar light diet Barq's diet Canada Dry Diet cherry Coke Diet Coke/Coca-Cola light Diet Coke Black Cherry Vanilla Diet Coke Citra/Coca-Cola light Citra Diet Coke Plus Diet Coke Sweetened with Splenda® Diet Coke with Lemon/Coca-Cola light with Lemon Diet Coke with Lime/Coca-Cola light with Lime Diet Coke with Raspberry Diet Crush diet Dr Pepper/Dr Pepper Zero diet Fanta/Fanta light/Fanta Zero/Fanta Free diet Freskyta diet INCA KOLA diet Kia Ora diet Krest diet Lift/Lift light diet Lilt/Lilt Zero diet Master Pour diet Mello Yello diet Mezzo Mix diet Minute Maid Soft Drink diet Nestea/Nestea light* diet Northern Neck diet Oasis diet Quatro/Quatro light diet Schweppes diet Seagram's* diet Sprite/Sprite light/diet Sprite Zero/Sprite Zero diet Squirt diet Tai/Tai light diet Vanilla Coke Disney Xtreme Cooler* Diva Dobriy Dogadan Dorna Dr Pepper E2 Earth and Sky Eight O'Clock El Rayek Enviga* Epika Escuis Eva Water Fanta Fanta Verdia Far Coast Felicia Finley Fioravanti Fire Five Alive Flavor Rage Fontana Fresca Fresca 1 Frescolita Freskyta Fresquinha Fress Frestea* Friolin Frisco Frugos Frugos Fresh Fruit Solutions Fruitia Fruitier Fruitopia Fruktime Frutina Frutonic Full Throttle Full Throttle Blue Demon Full Throttle Sugar Free Funchum Orange Drink Furusato Dayori FUZE Healthy Infusions GEORGIA GEORGIA Club GEORGIA Gold GEORGIA Grande Gini Girios Gira glacéau smartwater glacéau vitaminwater glacéau vitaminwater zero Gladiator Godiva* Belgian Blends Gold Peak Gold Spot Golden Crush Goombay Punch Goulburn Valley Grapette Groovy Guaraná Kuat light Guaraná Kuat Zero Hajime Haru No Mint Shukan Hawai Healthworks Heppinger Hero Hi Spot Hi-C Hires Hit Horizon Hot Point Huang Ice Dew Ice Dew 3+ Ice Tea Leao illy issimo* INCA KOLA Ipsei Izvorul Alb Jaz Cola Jericho Jet Tonic Jolly Juice Joy Joya Juan Valdez Juices To Go Just Juice Kani Kapo Kapo Zero Karada Meguri-Cha Kashaya Tea Keloco Keri Kia Ora Kildevaeld Kilimanjaro Kin Kinley Kist Kiwi Blue Kochakaden Kola Inglesa Koumisoukai Krest Kristal Kropla Beskidu Krushka & Bochka Kuat Kuat Guaraná Kuat light Kuli Kyun La Jolla La Vuelta Lanitis Lanitis Extra Lanitis Filaraki Leao Green Tea Leao Guaraná Power Leao Iced Tea Less Is More, Kinley Lift Lift Plus Lift Plus light Lilia Lilt Limca Limelite Limonade Linnuse Lion Love Body Maaza Mad River Malvern Manantial Mare Rosso Marocha Master Chill Master Pour Matte Leao Matusov Pramen Mazoe Mello Mello Yello Mer Mezzo Mezzo Mix Miami Mickey* Migoro-Nomigoro Minaqua Mineragua Minute Maid Minute Maid Active Minute Maid Antiox Minute Maid Deli Minute Maid Duofrutas Minute Maid Fruit Plus Minute Maid Heart Wise Minute Maid Just 10 Minute Maid Light Minute Maid Mais Minute Maid Nutri+ Minute Maid Premium Minute Maid Soft Drink Minute Maid Splash Mireille Mission Mone Montefiore Mori No Mizudayori Morning Deli Mother Mr. Pibb multiVita Nada Nagomi Nalu Namthip Nanairo Acha Naturaqua Natures Own* Nectarin Nestea* Nestea Choglit* Nestea COOL* Nestea Viteao* Nevada Neverfail Next Nico Nordic Mist Northern Neck NOS Nos Entendemos Oasis Odwalla Olimpija Orchy Paani Treated Water Pacific Orchard Pampa Paradise Sun Parle Pasazade Pearona Peats Ridge Springs Pibb Xtra Pibb Zero Piko Pilskania Planet Java* Play Energy Drink Pocket Dr Poiana Negri Polar Brew Poms Ponkana Pop Portello POWERADE POWERADE Advance POWERADE alive POWERADE aqua+ POWERADE Balance POWERADE light POWERADE OPTION POWERADE Zero Powerplay Premio Presta Presta light Pulp Orange Pulpy Pump Pumped Enhanced Hydration Pura Sol Qoo Quatro Quwat Jabal R'fresh Ramlosa Real Real Leaf Real Gold Rehab Relentless Rich Richy Riwa Roemerquelle Rosa Rosalta Roses Royal Tru Royal Tru light Safety First Safia Sahtain Samantha Samurai San Luis Sarsi Saryusaisai Schuss Schweppes Schweppes Abbey Well Seagram's* Seltz Sensation Sensun Gazoz SENZAO Shandy Shangri-La ShiZen* Shock Signature Sim Simba Simply Apple Simply Grapefruit Simply Lemonade Simply Limeade Simply Orange Smart Sobo Sokenbicha Solo Sonfil Soonsoo 100 Southern Sun Sparkle Sparletta Sparletta Iron Brew Splash Splice Sport Sprite Sprite 3G Sprite Duo Sprite Flavors Sprite Ice Sprite Remix Sprite Zero/diet Sprite/Sprite light /diet Sprite Zero Spur Squirt Stoney Gold Ginger Beer Sucos Mais Sunfill SURGE Svali Sveva Sweecha TaB TaB energy TaB X-Tra TADAS Tai The Spirit of Georgia The Wellness From Coca-Cola Thextons Thums Up Tian Yu Di/Heaven and Earth Tiky Toppur Top's Tropi Tropical Turkuaz Ultra Urge Urun V Florida 7 Valle Frut Valpre Valser Valser Viva Vanilla Coke Vanilla Coke Zero VAULT VAULT Zero Vegitabeta VICA Vio Vita Vital Wilkins Wink Winnie the Pooh* Yangguang Yangguang Juicy T Yo Conozco a Hugo Yoli Youki Yuan Ye

Dropbox plus Mercurial -driven development. Anyone tried that?

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 the equation; there's still the time consuming process of deploying the changes to "production". So i wonder if it would be a good idea to have a Mercurial repository sitting on a dropbox account and develop directly there. This way any changes to the source code would be instantly reflected on production.

I am aware that this is unthinkable for serious projects (the kind you get paid to do), but it can probably work for fun pet projects.

Do you have any experience with something like that? Share your thoughts, if you have any :)

Java Web Start (jnlp) simple example

UPDATE (2013/05/28): Since most people already know, WebStart is a bit of a crappy piece of tech with a bunch of limitations. The good news is there are alternatives :)

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 are required for the whole thing to work. Here's a brief explanation about each of them (in my creation order ;)):

src/org/Test.java : My source code. It's just a simple main that creates a JFrame and displays it; Manifest.txt : The manifest file used to create the jar file that gets served by Java Web Start; faren.jar : My application's jar. I'll explain how to create it in a while; faren.jnlp : The Java Web Start description file; faren.html : The html file that contains the button to start the application.

The first thing we want to do is create the source file. In the case of my simple test, here are its contents (blank lines removed for brevity): Test.java package org;

import javax.swing.JFrame; import java.awt.Dimension;

public class Test {   public Test() {     JFrame faren = new JFrame("Test");     faren.setSize(new Dimension(300, 300));     faren.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     faren.setVisible(true);   }   public static void main(String[] args) {     new Test();   } } Moving on to the jar manifest file, it basically just says what the main class will be: Manifest.txt Main-Class: org.Test Creating the jar is as simple as running the following command: jar cfm faren.jar Manifest.txt org It creates the faren.jar file, using the manifest file and the sources contained within the org folder. If - like me - you use Maven, you will have this for free using the app-assembler plugin, but for the test's purposes i didn't want to create a full maven project :)

Now we need to define a description file for the Java Web Start mechanism: faren.jnlp <?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="file:///Users/pedroassuncao/Desktop/jnlp_example">   <information>     <title>Dynamic Tree Demo</title>     <vendor>Dynamic Team</vendor>   </information>   <resources>     <!-- Application Resources -->     <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>     <jar href="faren.jar" main="true" />   </resources>   <application-desc     name="Dynamic Tree Demo Application"     main-class="org.Test"     width="300"     height="300">   </application-desc>   <update check="background"/> </jnlp> Just to explain a little bit of what is going on in here (the important parts), what you want to make sure is that the codebase property is set correctly to the absolute path where the html file will be served from (in the case of a final deployment this will be something like http://myserver/jnlp/myapp, but in this case i'm serving without a web server, hence the file:/// part). You will also want to define a minimum version for the virtual machine of the client (the 1.6+ part) and eventually extend this information with the <shortcut> tag, that allows you to ask web start to create a desktop icon for your application on the clients' computers. A full description of the structure of this file can be found here.

Finally, we need an html file that will show the java web start button. The following will suffice for now: faren.html <html>   <head></head>   <body>     <script src="http://www.java.com/js/deployJava.js"></script>     <script>       // using JavaScript to get location of JNLP file relative to HTML page       var dir = location.href.substring(0, location.href.lastIndexOf('/')+1);       var url = dir + "faren.jnlp";       deployJava.createWebStartLaunchButton(url, '1.6.0');     </script>     <noscript>       <a href="faren.jnlp">Launch</a>     </noscript>   </body> </html> If the client's browser supports javascript, this will use a special script from the java website that will ask to install the virtual machine if the client does not have it (or upgrade an existing one). If he doesn't support javascript it will just show a link that will try to launch the java web start (depending a lot on whether the user's file associations are correct (i.e. .jnlp files being assigned to the java executable).

Finally, with all this in place, point your browser to the place where you have the faren.html file and click the button; the application should launch.

By the way, does anyone know why my desktop shortcut is not being added on OSX? :)

Did a Russian scientist just invent an anti-aging pill?

He seems to be a very respected scientist in his field, with a lot of publications and a job at a very prestigious university. Even Gunter Blobel, a biochemist and Nobel laureate seems to respect him quite a bit. Is it just a couple of years until we are able to remain young and healthy - potentially - forever? Who never dreamed of living forever? I sure do!

Taken from here