Ramblings Of a Madman

Yeah, like i would know a good description…

Posts for Tag: software development

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

JasperReports - Unsupported major.minor version 51.0

Just ran into something a bit far fetched: My Jasper reports were not working in VOS, our JAVA Swing application at Inforviegas. It complained with an error along these lines: Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedClassVersionError: CCClient_1334580618412_476658 : Unsupported major.minor version 51.0

The only difference from business as usual was that i changed laptops.

We are using the jasperreports-maven-plugin to compile the reports from maven. In our pom.xml files we always define the maven-compiler-plugin target and source versions of the virtual machine. One would assume that the jasper plugin would use the same version of the maven-compiler-plugin, right? Wrong. It uses the default virtual machine set in your computer. And since i had Java 7 as the default and we are compiling to Java 6, the reports end up with the wrong java version, making them not show in our application.

Hope this helps some people save some time, since i couldn't :)

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

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 + 1 break end end Usage is: ruby count.rb <file> [show_at_most_n] If you have a file named "faren.txt" comprised of the following lines: test test awesome dude dude dude faren meran Running the script  with: ruby count.rb faren.txt Will yield the following result: (3) dude (2) test (1) awesome (1) faren (1) meran In addition, if you pass the "show_at_most_n" parameter (a number), it will only print that number of results. For example 2 will show the following: (3) dude (2) test

Idea - HTML WYSIWYG editor with Flickr upload support

The biggest problem with this, is that WP's interface to create posts is, again, awesome. You can find plugins for pretty much anything, especially to do tasks that are otherwise plain boring, like uploading pictures to your flickr account and instantly have them available in your post for inclusion. I've been trying to find something like that for those nice HTML editors out there (like tinyMCE and CKEditor), but so far have had no luck.

Anyone out there knows if something like that exists yet and where can i find it?

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 hacker's vein popups up every now and then to whisper the reasons why i should have something custom made :) The biggest problem with this, is that WP's interface to create posts is, again, awesome. You can find plugins for pretty much anything, especially to do tasks that are otherwise plain boring, like uploading pictures to your flickr account and instantly have them available in your post for inclusion. I've been trying to find something like that for those nice HTML editors out there (like tinyMCE and CKEditor), but so far have had no luck. Anyone out there knows if something like that exists yet and where can i find it?

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

NonUniqueObjectException- a different object with the same identifier value was already associated with the session

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 hibernate-managed object, this object becomes "detached" (meaning hibernate no longer has any control over it). So, when you attempt to save or update it in another session, hibernate will complain with that exception, because it can no longer tell which is the "true" version of the object.

The solution(s)? Look inside your code for places where you might be closing the session and take that out. That's the solution in the case where you are using a long session (one that spans the entirety of the application's life). In case you really want to close the session, you might consider using the session's merge() method, which basically merges the fields in both the attached and non-attached instances of the object, and performs an update.

Hope that saves someone half a day of debugging ;)

Earthquake information in Ruby

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" # url or local filecontent = "" # raw content of rss feed will be loaded here open(source) do |s| content = s.read end rss = RSS::Parser.parse(content, false) rss.items.each do |item| data = item.summary.to_s # Extract raw info data = data.scan( /alt\=\&quot\;([^>]*)W\&quot\;/).last.first # Remove html escaping data = CGI.unescapeHTML(data).gsub("°N", "").gsub("°", "") # Convert into coords lat = data.split(' ')[0] lon = data.split(' ')[1] # Print it print item.updated.content, " ", item.title.content, " ", lat, " ", lon, "\n" end Next step: Show this on a map :D