Archive for the 'Code' Category

How to resize an EBS (xfs formatted) partition

Saturday, December 20th, 2014

First of all, create a snapshot of your EBS volume. Then out of that snapshot you will be able to create your new volume.

However, when you detach the old one from your instance and attach the new one, you will still see the old available space with df

look at my /dev/xvdf/ available space (after mounting the new EBS volume)

ubuntu@ip-10-47-167-74:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       16G  5.9G  9.1G  40% /
udev            7.4G   12K  7.4G   1% /dev
tmpfs           1.5G  176K  1.5G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            7.4G     0  7.4G   0% /run/shm
/dev/xvdf        20G   19G  1.7G  92% /media/ebs/data  <<< this one

still 20G, I mounted a 80G one!

This drive has been formatted to use an xfs file system. In order to resize it, this is the command I used:

sudo xfs_growfs -d /media/ebs/data

output should be something like this

ubuntu@ip-10-47-167-74:~$ sudo xfs_growfs -d /media/ebs/data
meta-data=/dev/xvdf              isize=256    agcount=4, agsize=1310720 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=5242880, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242880 to 20971520

now let’s see the df -h output

ubuntu@ip-10-47-167-74:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       16G  5.9G  9.1G  40% /
udev            7.4G   12K  7.4G   1% /dev
tmpfs           1.5G  176K  1.5G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            7.4G     0  7.4G   0% /run/shm
/dev/xvdf        80G   19G   62G  23% /media/ebs/data

[bash scripting] How to get a file’s name without its extension(s).

Saturday, September 6th, 2014

Say you have an encrypted file file.foo.gpg and you want to make a shorthand command to decrypt that file, you’ll want the resulting file to be named file.foo (without the .gpg), or say you want the name, with no extension?), you can use bash’s magic variable voodo for that.

Screen Shot 2014-09-06 at 4.29.38 PM

A simple version of that script would look something like this:
Screen Shot 2014-09-06 at 4.34.26 PM

GRADLE: How to specify resources from different folders on your sourceSet

Tuesday, July 29th, 2014

Sometimes you need to have resources in your sourceset and these may come from different locations on disk, the official documentation is lacking in real world examples, or at least I just didn’t understand it very well, but from reading forums I finally got it to work.

In the example I specify what files to include/exclude from two different folders.
When the final .jar is created, they’ll keep the package path structure that lives inside the given srcDir folders.

If you just want to add these files (for some reason to the root of your resulting jar, you should make srcDir the full path to where the files live)

sourceSets {
    main {
        java {
            //your java source paths and exclusions go here...
        }

        resources {
            srcDir 'components/resources/src/main/resources'
            include '**/*.properties'
            include '**/*.png'
            include '**/*.gif'
            include '**/*.jpg'
            include '**/*.html'
            include '**/*.js'
            include '**/*.sh'
            include '**/*.dat'
            include '**/*.icc'
            exclude '**/*.DS_Store'

            srcDir 'common/vuze/azureus2/src'
            include '**/Messages*.properties'
            exclude '**/*.class'
            exclude '**/*.java'
        }
    }
}

GRADLE: How to copy files from another .jar into your resulting output .jar

Tuesday, July 29th, 2014

In our project we like to deliver a single jar as the final product, if you need to copy files that live on an existing jar into the Gradle’s output jar, this example shows you how to do that (and more)

jar {
    //this is how you change the name of the output jar
    archiveName='frostwire.jar'

    //some exclusion rules to keep your .jar clean
    exclude('META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF')

    //here we grab all the .class files inside messages.jar and we put them in our resulting jar
    from (zipTree('lib/jars/messages.jar')) {
        include '**/*.class'
    }

    //how to manipulate the jar's manifest
    manifest {
        attributes 'Main-Class': 'com.limegroup.gnutella.gui.Main'
    }
}

GRADLE: How to add a list of local .jar files to the build classpath

Tuesday, July 29th, 2014

Sometimes you don’t want/cant use maven repos, all you have is a bunch of local jars on disk that you want to use as part of your compilation classpath, and the freaking gradle documentation is too vague.

Here is an example:

dependencies {
    compile files('lib/jars/gettext-commons.jar',
                  'lib/jars/lucene-3.5.0.jar',
                  'lib/jaudiotagger.jar',
                  'lib/jars/h2-1.3.164.jar',
                  'lib/jars/messages.jar',
                  'lib/jars/slf4j-api-1.7.5.jar',
                  'lib/jars/jaudiotagger.jar',
                  'lib/jars/metadata-extractor-2.6.2.jar'
                  )
}

[SOLVED] Gradle: How to increase the Java Compiler’s available Heap Memory

Tuesday, July 29th, 2014

The documentation is not very clear on what all the available options are…
after much Googling and many different attempts finally figured out how to raise the maximum heap of the compiler from within the gradle.build script.

apply plugin: 'java'

compileJava {
    //raise heap
    options.fork = 'true'
    options.forkOptions.with {
        memoryMaximumSize = "2048m"
    }
}

Update:
So I’ve noticed this works great on MacOSX, but it doesn’t work at all on Windows 8.

The solution to increasing the JVM’s Heap has been to remove those options from gradle.build script and add a new file on the same folder as where your gradle.build file lives called ‘gradle.properties’

These are the contents that made it work for both Mac and Windows (I’ve still not tested this on my linux box)

org.gradle.jvmargs=-Xms256m -Xmx1024m

[SOLVED] Sublime Text 2: Git binary could not be found in PATH

Tuesday, July 22nd, 2014

Got this annoying dialog popping up on Sublime Text 2?
Screen Shot 2014-07-22 at 4.31.03 PM

Go to Preferences > Browse Packages …

Screen Shot 2014-07-22 at 4.33.02 PM

a Finder window will open, go to the “Git” folder, open the file called “Git.sublime-settings”

Look for “git_command” and set it’s value to the path of your git executable

Screen Shot 2014-07-22 at 4.31.47 PM

(you can find the path of your git executable on the Terminal by typing “which git”)

Screen Shot 2014-07-22 at 4.35.24 PM

How to change the default page when you open a new tab in Chrome

Friday, June 6th, 2014

Install the “New Tab Redirect” Chrome extension.

Screen Shot 2014-06-06 at 12.01.51 PM

Evil Chrome developers (or evil product managers forcing good developers) have hidden an old setting that used to be in chrome://flags, so now the simplest way to change it is with this extension

Once installed configure it to whatever you like, if you want it to open a blank page, set the default url to “about:blank”

Screen Shot 2014-06-06 at 12.08.06 PM

The real price of Bitcoin in Bolivares Fuertes: BitVen.com

Friday, May 23rd, 2014

I’ve just released a tool for Venezuelans looking to know what the ACTUAL price of Bitcoin is in Bolivares Fuertes, it’s called BitVen.com

Most price tickers out there don’t know about Venezuela’s currency control reality and they post the Bitcoin price using the Government’s official dollar exchange rate, the problem is, that it’s really hard to access US dollars at that rate because of all the government blocks, this has inevitably lead to a huge USD black market.

Screen Shot 2014-05-22 at 9.39.28 PM

BitVen tracks the price of Bitcoin using the current black market rate of the USD in Bolivares fuertes.

The app tells you the price of 1 Bitcoin in USD and VEF when opened, but it’s actually an interactive calculator, you can modify the amounts in any of the currencies and the equivalent value on the other two will be reflected as you type. For english speakers it will be a bit awkward seeing “.” as the thousand separator and “,” as the decimal separator, but this is a product with Spanish speakers in mind.

I made it thinking of my vision on what’s going to happen with Bitcoin in latin america, more specifically Venezuela, a country that actually needs bitcoin but doesn’t really know about it.
We’re currently in the initial phase of Bitcoin adoption, where you need to know what it is, what’s happening around it, and then you need tools like this to understand how the price fluctuates, for Venezuelan’s it’s very different as they have to deal with this dual-exchange situation, and sometimes you can see that even though the price rices for USD, the rise is not linear for BsF, as the price of the USD in the Venezuelan black market can be lower at the time.

I’ll be packaging it into an Android and iOS app as soon as I get the chance.

Technologies used
In case you’re wondering how it’s built, this is actually my first NodeJS app. I built a NodeJS service that fetches the Bitcoin price in USD from BitPay, grabs the USD/VEF price from DolarToday.org and spits out JSON. The page is done with plain HTML/Javascript, no third party libraries used for faster loading.

It was quite interesting working with NodeJS, I milked the s**t out of Javascript’s dynamic features to reuse code, by passing functions as parameters, and it was interesting to think the server interaction with callback after callback, NodeJS development is living in callback land.

Top Eclipse (IDE) features I can’t live without

Wednesday, May 7th, 2014

(If you are in Windows, replace “Cmd” for “Ctrl”, and “Option” for “Alt”)

Cmd + 1: Create variables out of function’s outputs, get suggestions to fix issues.

“Shift + Cmd + T”: Open Type.

“Shift + Cmd + R”: Open Resource.

Select element and press “Option + Cmd + R” to rename a class, variable, method, the refactor will be performed throughout the entire project flawlessly.

Select element and press “Cmd + T”: Show Type Hierarchy, great to know what classes implement an interface, or what classes extend an abstract class.




  • Categories

  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • October 2009
  • September 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004