The GNU of Life, the Universe and Everything

November 18, 2012

Xcom : Enemy Unknown Tech Tree plus Armor and Weapon Stats

Filed under: games — Tags: , , , , , , , — Pedro Carvalho @ 11:41 am

Xcom : Enemy Unknown Tech Tree

XCOM: Enemy Unknown is a great game but the tech tree left me terribly confused. The existing tech trees graphs ( on which i based mine ) helped a bit, but i thought there was plenty of room for improvements.

It turned out like this. I hope it helps you!

XCOM:EU – tech tree ( High Resolution )

XCOM:EU – tech tree ( Low Resolution )

Also, here’s the SVG version for your immediate changes. Feel free to alter it. Let me know if there’s anything wrong with it.
XCOM:EU – tech tree ( SVG )

Fonts used:

xolonium by Severin Meyer ( GNU General Public License )
Lavoir by Alex Chavot ( SIL Open Font License )
Tulpen One by Naima Ben Ayed ( SIL Open Font License )


August 20, 2012

Javascript tests and results

Filed under: html, javascript — Tags: , , — Pedro Carvalho @ 6:26 am

I’ve been testing some basic javascript functions in the awesome Some confirmations about the native browser code being faster, but strangely, there’s a huge difference in performance. I started wanting to know the difference between using a strange js code i found online. It used .html().html("<img [...]") every cicle. Surely this wasn't the best way to handle a photo gallery counter. 

getElementById vs jQuery id selector

run the test: jquery id vs document.getElementById
jQuery ID :  $(“#foo”);

result: 305,690 92% slower

document.getElementById : document.getElementById(“foo”);

result: 3,824,633 fastest

jquery id vs getElementById


Unless i did something terribly wrong, native implementation is way faster. I would expect to be faster, but not in this order of magnitude.



jQuery 1.8 selectors: id vs class vs tag vs pseudo vs. attribute

run the test: id vs class vs tag vs pseudo vs. attribute selectors
There’s a lot of results on this test, and almost every entry points to the $("#foo") selector being the fastest, class $(".bar") and tag $("blockquote") on the same range, and pseudo and attribute $(":hidden") and $("[name='baz']") are really slow.

jquery selectors 1

appendChild VS jQuery appendTo

appendChild vs appendTo
Next, i created a test for appending a child node to a html element. the element was created outside the test.

appendChild :  document.getElementById(‘testc1′).appendChild(newdiv);

result: 2,087,401 fastest

appendTo : $(newdiv).appendTo(‘#testc1′);

result: 8,250 100% slower

appendChild vs appendTo


Again, i wasn’t expecting such a huge difference between native and jQuery performance.

Creating complex elements

run the test: creating and appending elements (by WTK)

The following test tries to append several html elements
Passing full html string to jQuery

var elements = "<div><table><tr><td>1</td><td>2</td></tr></table></div>";


Create elements by hand but still using jQuery

function create() {
  return $("<div>").append($("<table>").append('tr').append('td'));

Using innerHTML

var elements = "<div><table><tr><td>1</td><td>2</td></tr></table></div>";
var div = document.createElement('div') = 'mycustomdiv'
div.innerHTML = elements;

insert elementsinsert elements firefox ie other


Sadly, the browser implementation differs greatly from chrome to the rest, so innerHTML is still a bit and miss.

Creating a image node with attributes

What started as a simple gallery turned out as a great opportunity to do these performances tests. The source didn’t have a license and the code behave so badly, that isn’t wor

Test Ops/sec
 no jquery

var newimg = document.createElement("img");	 
newimg.alt = "Test Image";	 
newimg.src = '';	 
newimg.onclick = function(){ swapCase();  };	 
$('#testc2').append($('<img>', { 
    alt : "Test Image",
    src : '',
    click: function(){
8,575 41% slower
jquery alternative
$('#testc3').append( $(document.createElement("img"))
        src: '',
        alt: 'Test Image'
7,950    49% slower

March 16, 2012

How to make Cucumber run faster

Filed under: Ruby — Tags: , , , , , , , — Pedro Carvalho @ 3:08 am

Speed up the startup time of cucumber for TDD/BDD tests

Getting started with Behaviour Driven Development with Cucumber and noticed that it takes more time to startup than actually run the scenarios.

Compare this:

2 scenarios (2 passed)
4 steps (4 passed)

real 0m16.013s
user 0m14.850s
sys 0m0.814s

Cucumber reports 0m2.252s but time says 0m16.013s, thats ~~14seconds of difference.

Remember: user time represents the time the application spent on user-mode, actually running the code, where as sys represents the time spent on kernel. real is the full time from start to finish

Using spork as a DRb server

(DRb = Distributed Ruby server)
Note from spork site

Because Spork uses Kernel.fork, it only works on POSIX systems. This means Windows users are not invited to this party. Sorry :(

For your rails app, follow this procedure:

Add spork to your Gemfile

gem 'spork'

Run bundle install

and rails g cucumber:install --spork

Finally run spork server on the background:

bundle exec spork cuc &

And happily run tests:

cucumber features/...

The conclusion: it works!

2 scenarios (2 passed)
4 steps (4 passed)

real 0m3.946s
user 0m0.658s
sys 0m0.059s

March 8, 2012

Syntax hightlight theme for Ruby/Rails/Haml in Aptana

Filed under: Aptana, Ruby — Tags: , , , , , , , , , — Pedro Carvalho @ 12:21 am

I have a thing for code and colours. Let it be lolcode, lpsolve syntax for whatever the editor i’m using at the time, i have to tweak it.

This time i’m learning Ruby/Rails/Haml and whatnot. My favorite editor for WebDev has been Aptana with the Clouds theme, (a bit edited already) but it didn’t support ruby. So here it is “Clouds of Ruby”.

What does Clouds of Ruby look like?

Clouds of Ruby :: Ruby/Rails

Ruby/Rails Theme for Aptana

Clouds of Ruby :: HAML

HAML Theme for Aptana

Where to get Clouds of Ruby?

download Clouds of Ruby Theme. I recommend the Anonymous Pro font to go well with it.

To use, go to Preferences->Aptana Studio->Themes->Import. Change at will and have fun coding!

January 18, 2012

Stop internet censorship. Say no to PIPA and SOPA

Filed under: Freedom — Tags: , — Pedro Carvalho @ 1:36 pm

Today’s the day of the world stood against the proposals that would create laws to censor the internet based on denounces without due process!

Although you may have heard about SOPA, please take note that there’s a similar proposal called PIPA that is also being discussed but is not getting attention.

If you live in the USA,  please write or call your representatives, or use this form: to stop PIPA and SOPA.

These proposals are also very dangerous for everyone outside the US. Although these are US based laws, don’t forget that many domains that have a .com, .org, or .net are considered as domestic to the USA, so they fall under these laws jurisdiction. We know that corporations have been influencing the European governments like the recent cases of France, Portugal and Spain, to push similar laws into our own civil codes.  A censored internet is the end of public sharing of knowledge and we all have been thankful for this. So thank you for taking action!

say no to PIPA and SOPA

say no to PIPA and SOPA

December 17, 2011

Lpsolve Syntax Highlight for Geany IDE

Filed under: Geany — Tags: , , , , , , , — Pedro Carvalho @ 12:50 am

Add Lp Solve extension

Lp solve files Syntax highlight for Geany

An example of Lp solve files Syntax highlight in Geany

First, we need to add the extension file, so geany knows what file it can associate to lp solve files.

Either go to:  Tools -> Configuration Files -> filetype_extensions.conf

or:  edit directly the file in

Linux: ~/.config/geany/filetype_extensions.conf

Windows 7 :  c:\Users\username\AppData\Roaming\geany\filetype_extensions.conf

and add a new line with


Download Lp Solve syntax highlight file

Next, download this syntax highlight file:  filetypes.Lpsolve.conf

and place it in ~/.config/geany/filedefs/ (Linux)

or c:\Users\username\AppData\Roaming\geany\filedefs\ (Windows 7)

More information on syntax highlight

Note:  if not bothered to download this file, you can add the extension to any existing filetypes, for example:


Many thanks to editor.

November 29, 2011

how to open Visual paradigm projects directly from KDE

Filed under: kde4, linux — Tags: — Pedro Carvalho @ 6:32 am

oddly enough my installation of Visual Paradigm set its type to application/zip.

When i try to open it, it uses the same applications that other .zip files use.

Sure i could right-click + open with + Visual paradigm , but ….

So instead we’re going to create a new file type for that .vpp extension.

Create a new filetype in KDE

1 – Add a “x-vpp” type.

2 – select it (it down the list, inside the application category)

3 – Add a filename Pattern:

4 – Add an Application
* browse to your “Visual Paradigm for UML” binary file ( /path/vp/bin/Visual_Paradigm_for_UML_8.3 )

5 – Select an icon
* check the “resources” directory in your VP installation ( path/vp/resources/vpuml.png )

6 – press OK

Ok, now we need to edit the culprit of this mess:

Change the mimetype for Visual Paradigm for UML

edit the ~/.local/share/applications/Visual_Paradigm_for_UML_8.3.desktop

and change the mimetype to:


Restart your file manager

and we’re done! re-open your konqi/dolphin and .vpp files will always open with VP and your .zip will never again
be open with VP!

March 19, 2011

Patch portage to be more quiet

Filed under: gentoo, linux — Tags: , , — Pedro Carvalho @ 8:20 pm

Gentoo Live Linux 10.0
Gentoo linux is alive and well and just released a new Gentoo Linux Live.  It features Linux Kernel 2.6.37 (with Gentoo patches). It comes will all desktop environments. Especially if you are looking for KDE 4.6 SC here’s the best way to start.
It also includes (3.2.1), GIMP (2.6.11), Inkscape (0.48.1), Blender (2.49b), and many more. They are all packed in either the x86/x86_64 or the x86_64. If you like it, you’ll need to install Gentoo with the Instalation CD.

So a few days after the celebrated news of 11th release here’s a patch for portage to make it quiet and nice.

Those extra verbose warnings really annoys me,  because emerging something keeps showing me all the licensed packages that are masked, broken packages or masked.  So i fixed the !!! existing preserved libs:
” ,  “!!! The following installed packages are masked:” and !!! There are updates currently masked by LICENSE changes.” messages.

You can revert to the verbose warnings with the new flag “–extra-verbose”.

All it does is remove the list of packages shown after doing a emerge, and improves the speed because it doesn’t calculate any of it (particular when figuring out the preserved libs) and only shows a single line warning about them.

The patch is for portage-2.2.0_alpha26 (which is totally a must so you can play around with @sets)

Where to get the patch


How to apply the patch:

on the /usr/lib/portage/pym/ directory

patch -p1 -i patch-2.2.0_alpha26

The handbook is always a good idea to keep around ;)

(the image was taken from the Gentoo Live 10.0)

December 14, 2010

How to format a usb pen or mp3 player the right way

Filed under: console, linux — Tags: , , , — Pedro Carvalho @ 1:11 am

In a short line:

# mkfs.vfat -vc -F 32 -n “zen stone” -S 2048 /dev/yourdevice

The explanation:

free the gnu -  lego mp3 player

free the gnu - lego mp3 player

-v Verbose execution.

-c Check the device for bad blocks before creating the file system.

-F FAT-size
Specifies the type of file allocation tables used (12, 16 or 32 bit).
If nothing is specified, mkdosfs will automatically select between 12 and 16 bit, whatever fits better for the filesystem size.  32 bit FAT (FAT32 format) must (still) be selected explicitly if you want it.

-n volume-name
Sets  the volume name (label) of the filesystem.  The volume name can be up to 11 characters long.  The default is no label.

-S logical-sector-size
Specify the number of bytes per logical sector.  Must be a power of 2 and  greater  than or equal to 512, i.e. 512, 1024, 2048, 4096, 8192, 16384, or 32768.

change “youdevice” for your own. Find out which is by checking your dmesg after plug-in the usb device for  something like:

  • sde: sde1
  • sdb
  • etc…

You might want to try this flag too:

-I Normally you are not allowed to use any ‘full’  fixed  disk  devices.
mkdosfs  will complain and tell you that it refuses to work.  This is different when usind MO disks.  One doesn’t always need partitions on
MO  disks.   The  filesytem can go directly to the whole disk.  Under other OSes this is known as the ‘superfloppy’ format.

This switch will force mkdosfs to work properly.

September 22, 2010

Yet another ssh brute force attack and how to protect against it with iptables and sshguard

Filed under: console, Security — Tags: , , , , — Pedro Carvalho @ 9:20 pm

ssh brute force attack

By chance, i looked into syslog ( /var/log/syslog ) and saw a ssh attempt to login from a ip outside local network. It was a brute force attack that started 7 days ago.. See down the post how to protect ssh from further attacks.

Looking at the logs ( tail -n 200000 /var/log/syslog ) noticed that the attack started on:

Sep 15 21:01:37 cerval sshd[13101]: Failed password for root from port 42023 ssh2

then the attack went on …

I checked the logs and saw the attack. stopped ssh. no more fun for you :(

I decided finally, after 6 years of laziness to build up some security.

Getting started with iptables

The guys at netfilter created, omnipresent on most of Linux machines, a packet filtering system called iptables.

The iptables Rules

For creating a bash script to create all the rules need, i used this online iptables wizard. (don’t forget to remove “LINWIZ-” from the script created)

Running iptables

Next run the script sh, save it /etc/init.d/iptables save, and then start, stop and start iptables again ( /etc/init.d/iptables start; /etc/init.d/iptables stop; /etc/init.d/iptables start )

and check if the rules are active with iptables -L -v

To get a better understanding check Stateful Firewall and Masquerading on Linux

Protecting ssh

Luckly gentoo portage has sshguard, which has lots of nice features!
Unmasked it to use a decent version (portage has 1.0 as stable, 1.4 as latest, but sshguard is v1.5rc4, which is the last RC planned before 1.5 stable. )

and then, emerge -av sshguard.
Its FAQ has the script to use for booting but the “-l” option wasn’t working on this version, so i used this instead

#! /bin/sh
case $1 in
    tail -n0 -F /var/log/auth.log | /usr/local/sbin/sshguard &
    killall sshguard
    echo "Use start or stop"
    exit 1

Add to the rc levels to ensure it starts at every boot:

rc-update add sshguard default

If you are using syslog-ng with sshguard

On Gentoo, just add  this to /etc/syslog-ng/syslog-ng.conf:

#create a new destination for sshguard
destination sshguardproc {
        template("$DATE $FULLHOST $MESSAGE\n"));
#creates a filter called f_sshlogs for auth and authpriv system logs
filter f_sshlogs { facility(auth, authpriv) and match("sshd"); }; # for sshguard

log { source(src); filter(f_sshlogs); destination(sshguardproc); };

Restart sshd

Start ssh again! /etc/init.d/sshd start

Older Posts »

The Shocking Blue Green Theme. Create a free website or blog at


Get every new post delivered to your Inbox.