Archive for the 'Code' Category

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.

How many lines of code are there inside Bitcoin-Core client?

Wednesday, April 30th, 2014

According to cloc this is the line count breakdown, 87% of the project is all C/C++ header files and code.

http://cloc.sourceforge.net v 1.60  T=7.23 s (72.2 files/s, 43792.9 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C++                            244           9985           6246         211500
C/C++ Header                   188           5346           4617          35399
Bourne Shell                    26           2576           2571          20090
make                            12            905           1105           7221
m4                              17            376             98           3697
Python                          18            333            224           1615
HTML                             3             85              0           1136
YAML                             8             21            115            545
C                                1             43             11            336
Objective C++                    2             37             14            153
CSS                              1             10              1             78
IDL                              1              1              0             20
XML                              1              0              0             10
-------------------------------------------------------------------------------
SUM:                           522          19718          15002         281800
-------------------------------------------------------------------------------

Setting up Eclipse as your IDE for Bitcoin C++ development on MacOSX.

Sunday, February 9th, 2014

If you are a Java developer used to the productivity levels achieved by working with eclipse’s code navigation, code completion and refactoring tools, it’s worth your time staying in eclipse for any sort of C++ development.

Screen Shot 2014-02-09 at 1.03.21 PM

This post refers specifically to getting your eclipse environment to work with a particular C++ Open Source project, The Bitcoin Project.

Before you start setting up eclipse, please make sure you can build Bitcoin from the command line, this way you know that you have everything necessary to build Bitcoin, even if you’re still getting a few errors showing in Eclipse, in the end Eclipse will be using the Makefiles provided by the project whenever we need to compile (and it can do so incrementally when possible saving you a lot of compilation time)

I’m assuming you have installed:
- eclipse
- eclipse CDT tools, up to date for the version of eclipse you’re working with (I’m still working with Juno)
- Qt/Eclipse plugin (optionally)
- All the dependencies (autoconf automake berkeley-db4 boost miniupnpc openssl pkg-config protobuf qt gdb) necessary to build Bitcoin which are easily installable via HomeBrew.

1. Let’s import the bitcoin/ project to our workspace.

File > Import > Existing Code as Makefile Project

Screen Shot 2014-02-09 at 12.41.45 PM

 

Look for the bitcoin/ git checkout folder, and make sure you use the GNU Autotools Toolchain

Screen Shot 2014-02-09 at 12.43.05 PM

 

Click Finish.

2. Fixing the C++ compiler Path and Symbols.

Right click on the project containing folder in the Project Explorer > Properties.
Go to C/C++ General > Paths and Symbols > Languages: GNU C++ >  “Includes” Tab and make sure it looks something like the screenshot below (I got those paths by looking at  the  ones used by the Makefiles in the Bitcoin. Hit Apply , OK, then wait for the reindexing, you might still have a few weird errors because of how the compiler checking settings are.

Screen Shot 2014-02-09 at 12.55.38 PM

3. Remove a few more issues like “Error: Invalid arguments candidates are: void resize(?, int)."

We open again the project Properties, this time we go to C/C++ General > Preproessor Include Paths, Macros, etc.
Click on the Providers tab and make sure “CDT GCC Built-in Compiler Settings [Shared]” is checked. Hit Apply, OK, wait for reindexing.
If there are still errors, you might want to just delete them and refresh the project (F5 on the project folder in the Project explorer), all errors should be gone by now.

Screen Shot 2014-02-09 at 1.01.25 PM

Now start working just as fast as you’re used to with Java on Eclipse.

 

Code completion…

Screen Shot 2014-02-09 at 1.09.39 PM

 

Project wide renaming refactors in seconds…

Screen Shot 2014-02-09 at 1.10.07 PM

 

 

Find references of variables, methods, classes (Cmd+Shift+G)

Screen Shot 2014-02-09 at 1.23.37 PM

 

Find all the implementations of an interface (Cmd+T)

Screen Shot 2014-02-09 at 3.34.39 PM

and best of all

Interactive debugging with gdb*

Screen Shot 2014-02-11 at 1.21.07 PM

and all the tools you know and love from Eclipse.

*Setting up GDB debugging

To do step by step debugging you can use gdb, if you don’t have it installed just go to your Terminal and type brew install gdb.

On your command line, execute your Makefile to create an executable, once it appears on your Project Explorer you can Right click on it Debug As > Debug Configuration…

Screen Shot 2014-02-11 at 1.31.43 PM

then make sure you have set gdb as the executable debugger in the “Debugger” configuration tab, then just set your breakpoints and debug away!

Screen Shot 2014-02-11 at 1.32.00 PM

Not so fast… :(

As of Mac OSX 10.9, Apple decided that you cannot use gdb unless the gdb executable is signed with a certificate, they want you to use their super duper lldb debugger, but it’s still not compatible with Eclipse, you know, so you use their XCode IDE instead of what you want to use…

Anyways, signing the gdb at /usr/local/bin/gdb is not that hard.

To sign it you can create a certificate, or use an existing developer certificate. In my case, I already had a Mac Developer certificate so it was a very simple process, just issuing a single command in the Terminal and I finally got rid of the "Unable to find Mach task port for process-id 93213: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))" error.

codesign -s “Name of my certificate here” /usr/local/bin/gdb

Then I tried debugging, I got a password dialog to verify I was the owner of the certificate, and then gdb could take over and then I could do my step by step debugging, with the ocassional crash.

Happy Hacking.




  • Categories

  • 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