Friday, December 5, 2014

Putting Groovy on Mint (and other Linux distros) the easy way

Installing Groovy on any Linux distro is a pain in the ass. Generally, the procedure is:

  1. Install the requisites. This could be an involved process because you could be potentially install a lot of stuff but at minimum just need Java.
  2. Download the binaries for groovy. If your Linux distro has a repo like Debian, I don't recommend using it because it not the latest.
  3. Do a bit of file handling and doing a bunch of sym links to the binaries.
  4. Configure your bash shell for groovy. Just like step 3, not fun and just plain tedious.
Fortunately for me, I've found a much easier way to do these steps with GVM. GVM is a tool for managing parallel Versions of multiple Software Development Kits on most Unix based systems. Inspired by Ruby's RVM, it's a convenient command line interface for installing, switching, removing and listing Groovy libraries. GVM call these libraries as candidates.

Just do this to install GVM:

curl -s get.gvmtool.net | bash

And then do this to install Groovy.

gvm install groovy

That should install the latest version of groovy and we're off and running with groovy development.

Thursday, November 27, 2014

Jasper Reports, 1kb PDFs and "I swear they did this on purpose"

I ran into this seemingly weird situation with Jasper Reports 5.0.1 where I was getting 1kb size PDFs which was weird. So after doing *lots* (lots) of debugging I couldn't find anything wrong. The lines where pretty straight forward:

  InputStream is1 = evalSummaryReportPage1.getResource().openStream(); //jrxml source
  Map reportParams1 = new HashMap(); // standard hashmap
  reportParams1.put(......)
  ..
  ..
  JasperDesign page1Design = JRXmlLoader.load(is1);
  JasperReport page1Compiled = JasperCompileManager.compileReport(page1Design);
  JasperPrint page1 = JasperFillManager.fillReport(page1Compiled, reportParams1); 

  JRPdfExporter exporter = new JRPdfExporter();
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, page1);
  exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, filename); 
  exporter.exportReport();

Until I found about JREmptyDataSource class. Apparently the fillReport() method of the JasperFillManager doesn't do shit when it doesn't has a third or the datasource parameter. It was bullshit because the same fillReport methods is overloaded and can be called with only two parameters. You can then compile with no problems or warnings. A warning would have been nice but no. I swear the Jasper devs did this on purpose just to fuck with me.

So to fix this shit:
  ..
  JasperDesign page1Design = JRXmlLoader.load(is1);
  JasperReport page1Compiled = JasperCompileManager.compileReport(page1Design);
  JasperPrint page1 = JasperFillManager.fillReport(page1Compiled, reportParams1, new JREmptyDataSource()); 
  ..
There, it now correctly generates the report.

zzzzzzzzz

Thursday, November 20, 2014

Why u no format SQL SQL Server Management Studio

Microsoft probably just loves developers but not DBAs because I find it amazing that the SQL Server Management Studio (SSMS) doesn't have a format SQL thing. It has the other stuff like Upper or lower case text, indent, undent, comment and uncomment BUT no freakin' format SQL. That is bullshit.

Of course, you could argue that I should buy some of those 1000 dollar plugins like Redgate SQL Prompt but that seems excessive. I just need to format SQL. That's it.

So after googling a bit on this I was able to find PoorSQL which a not only a website that formats SQL but is also a plugin in for SSMS and Visual Studio. Amazingly, it's also a open-source and free.


Friday, November 7, 2014

All up in the clouds

I haven't posted in a long while because I've been busy moving into a new place. Things have settled a bit and I'm starting to write again. This time I'm talking about the two cloud services I've been using: Google App Engine(GAE) and DigitalOcean(DO).

GAE is a platform. Think of folder where you put files and have a specific API to use to interact with your data store. The data store here is Google's. Of course, you could use other ones external from Google like mongolab if you into the whole NoSQL thing. The upside to this is you don't have to worry about maintaining servers, binaries and such. It makes you focus on your app. The downside though is that the "folder" is a sandbox. You are limited to what the API has.

DO is a VM. Think server. You can start off with a bare bones Linux server - there are Debian and Redhat variants - or if you could start off with a complete configured LAMP server. Either way, you will manage this via an SSH connection. The downside, will you have to manage that VM and if you happen to be a sucky (or worst lazy) administrator you might end up screwing up a lot. The upside is you have full control.


Sunday, September 14, 2014

SparkJava and Webjars

I've been playing around with Per Wendel's Spark framework. It's a micro framework inspired by Sinatra and it's in the same vein of node.js and ruby-on-rails. Just the thing is, Spark is Java and by being Java, the whole Java ecosystem is available.

I started learning Spark via the readme section of the site. Once you get through the basics, you start working in your favorite Java stuff. For me, the first thing I wanted to work in is Webjars.

Webjars is this thing we it pack jars with client-side libraries. This allows us to manage client-side libraries using various Java build tools like maven, ivy or gradle.

Adding webjars into an maven project is painless. It's a dependency. Here's a webjar for bootstrap3:

<dependency>  
    <groupId>org.webjars</groupId>  
    <artifactId>bootstrap</artifactId>  
    <version>3.2.0</version>  
</dependency>  

With the webjar added. We now need to tell Spark about it and serve them files. This took me a couple of hours to make it work. I had to figure out that webjars unpack to /META-INF/resources folder and tell Spark about it. It also helped that I looked at Spark's source code and realized that is a special Java servelet.

// Serve our client-side files from here
staticFileLocation("/META-INF/resources"); 

And reference it in our template like this:
<link rel='stylesheet' href='webjars/bootstrap/3.1.0/css/bootstrap.min.css'>

There. Spark app with webjars.

Tuesday, September 2, 2014

Poor man's responsive web testing

Websites use to be easy to make and test but with the rise of mobile devices has slightly complicated things. This is the whole responsive web design thing.

Now I bet you've typed "browser responsive testing" into Google and found Browser Stack. And I bet you found out they are not exactly cheap. So we do the next best thing and setup Matt Kersley's solution.



Matt also has a github repo for this with instructions to have it installed locally. You can do this by either setting up a XAMPP install or local apache.

Not exactly pixel perfect but close enough.

Happy testing!

Thursday, July 24, 2014

Repo spring cleaning

If you are reading this entry then you probably tried to access one of my repos from either bitbucket or github. I apologize because I have delete that repo.

I felt a need to clean up my repo because they are bit dated and usually isn't very good as far as code is concerned. Most of the code were written "in the small" and doesn't really lend to good code.

The current list of repo I've delete:


  • https://bitbucket.org/jaypax/devfestcdo-angular (7/24/2014)

I will be updating this list as time goes on.


Monday, June 9, 2014

Somehow I got it to work: Tapestry 5.4-beta10 and Google App Engine

Aside from a bunch of crummy errors and missing files, I manage to to get Tapestry 5.4-beta10 to run in a Google App Engine instance. Here's what I learned:
  1. Java 8 and Tapestry 5 don't like each other. A bunch of guys reported it like Matt Raible. There's a work around and it isn't exactly safe for production (yet).
  2. YUIcompressor is missing again from the staging repo.
  3. You need to MAKE sure that your GAE instance name matches your appengine-web.xml application name. 
So how to go about getting your Tapestry5 into GAE. 
  1. Start by creating a Tapestry 5 project via maven. Which one though depends on what version of Java is on your dev machine. I'm running Java 8 so I had to use something greater than 5.4-beta4. I just updated the pom.xml and ran mvn clean compile.
  2. Add a appengine-web.xml to the src/main/webapp/WEB-INF folder.
    <?xml version="1.0" encoding="utf-8"?>  
     <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">  
       <application>YOURAPPNAMEHERE</application>  
       <version>1</version>  
       <threadsafe>true</threadsafe>  
       <sessions-enabled>true</sessions-enabled>  
     </appengine-web-app>
    
  3. Edit the pom.xml to include google app engine devserver. Look for the plugins section and add this lines.
    <!-- Run the application using "mvn appengine:devserver" -->  
     <plugin>  
               <groupId>com.google.appengine</groupId>  
               <artifactId>appengine-maven-plugin</artifactId>  
               <version>${appengine.target.version}</version>  
               <configuration>  
                         <enableJarClasses>false</enableJarClasses>  
                         <port>8182</port>  
                         <address>0.0.0.0</address>  
               </configuration>  
     </plugin> 
    
    Also, add these values in the properties node:
            <appengine.target.version>1.9.6</appengine.target.version>
    
  4. Run mvn appengine:devserver
    There is where it gets hairy, if it fails to run, check the stack trace. If it says yuicompressor is missing then comment it out in the pom.xml and then make sure to run the app in dev mode by adding this line in the AppModule.java in the contributeApplicationDefaults method:
       configuration.add(SymbolConstants.PRODUCTION_MODE, false);
    
    There should clear it up. If there are more problems refer to the appengine docs for maven.
  5. If all goes well and you should have a running Tapestry5 app running locally inside a appengine devserver instance. The next step is to upload it to the appengine servers because that's the whole point.
  6. Run mvn appengine:update
    There should open a web page where authentication code to paste into the command line. Also, I do hope you already created a matching app engine project. No? You are a dumbass.
Here is my tapestry5 after all of that.

Monday, May 26, 2014

SoundManager2, jquery, angular and the Hotline Miami OST - Part 1

Sound Manager 2
I haven't written anything in the last 30 days. I've been a busy and lazy (among other things). But I had to write these things down before I forget again. I'm planning to do this in 2 parts so it won't be that long to read.

Sound Manager 2
Sound Manager 2 is this JavaScript library simplify playing audio on a web page. Think embedded players like SoundCloud and such. It's pretty nifty with fail-over support for Mp3 via Flash if you somehow have a retarded web browser who can't play an HTML5 audio tag. The whole point is you end up with a single API to use to play audio files IF only it didn't have a few gotchas.

The SM2 Gotchas that got me in the ass
  • Read the requirements page closely. Don't do what I did and dove straight into the API and got hung up on a few issues (some Flash crap and arbitrary seeking) which could have been resolved quite easily and quickly if I have READ THE FUCKING REQUIREMENT'S PAGE a bit more closely. 
  • Variable Bitrate (VBR) MP3s bad, Constant Bitrate (CBR) MP3s good
  • HTTP 206 Header (Partial Content). If you are like me and got a soup nazi for web administrator, use curl or Fiddler and test your Apache because it might be turned off. We don't want a "No soup for you" incident.
Using SM2 and turning it into a Jquery plugin
SM2 can easily be used with Jquery and turn it into a plugin. The challenging parts are deciding on how to deal with the settings (and there are a lot of SM2 settings) and how to handle the sound objects.

For the setting, I decided to go with sensible defaults that can be overridden and use jquery's $.extend function to merge it. It more or less looks like:
// default settings
var settings = {
    autoplay: false,
    loop: false,
    playNextOnFinish: true,
    hideTrackDetailsAfterPlay: false, /* N (Number) seconds, or false (Boolean) to always show it */
    soundManagerMultiShot: false, /* let sounds "restart" or "chorus" when played multiple times..*/
    soundManagerStream: true,  /* allows playing before entire file has loaded (recommended) */
    soundManagerSwfURL: 'swf/', /* path (String), relative to your html page */
    soundManagerFlashVersion: 9,
    soundManagerDebug: false, /* displays the SM2 debug info into the page and in the console */
    soundManagerHandleFlashBlock: true,
    soundManagerPreferFlash: false,
    soundManagerHTML5Audio: true,
    soundManagerFlashLoadTimeout: 1000
};
    .
    .
    // jquery plugin
    $.fn.smsplayer = function(options){
      if(options){
         $.extend(settings, options); // Merge options to settings
      }
      return this.each(function (){
         ....
      }
    } 

Usage therefore would look like:


As for the Sound objects, I decided to to handle them in an array.

var tracks = [],trackIDs = [];
.
.
$("#player").find('#playlist li > a').each(function(i) {
  var soundID = 'sms_sound_' + i.toString();
      $(this).addClass(soundID);
      trackIDs.push(soundID);
      var sound = soundManager.createSound({
                  id: trackIDs[trackIDs.length - 1],
                  url: $(this).attr('href'),
                  whileplaying: function() {
                    Player.prototype.updateTime(this.position, this.durationEstimate);
                  },
                  whileloading: function() {
                    Player.prototype.updateLoading(this.bytesLoaded, this.bytesTotal);
                  },
                  onfinish: function(){
                    isPlaying = false;
                    $('#playlist .playing').removeClass('playing');
                        
                    if(settings.autoplay){
                       var nextSound = Player.prototype.getNextTrackFrom(trackIDs, this.id);
                       currentTrackID = nextSound;
                       $('.' + currentTrackID).parent().addClass('playing');
                       Player.prototype.playSound(nextSound);   
                    }
                         
                  }
       });
       tracks.push(sound);

I'm going to explain the Hotline Miami OST in part 2.

Wednesday, March 19, 2014

4 code editors you should be looking at (and none of them is Atom)

  1. Notepad++. I like it because its snappy and an outright replaced to notepad on Windows systems. It also have a bunch of plugins for everything. My favorite use of Notepad++ is to view and format JSON, It's also a pretty capable source code editor with line numbers and color highlighting for a lot of languages.

    Notepad++

  2. Brakets. This free code editor is geared towards JS and HTML5 scripters - frontend people; it has this cool feature called "live html" where you connect Brackets to a live server and "edit" the site live. It also has a lot of plugins, I especially like the color/swatch plugin where when you edit CSS colors, it pops up a color selector helping you pick the right shade of blue or whatever. It's also nice that it understands CSS dialects like Less and SaSS.

    brackets.io

  3. Lighttable. Although its sort of still in the dev stages it's quite stable on my ElementaryOS machine. It HAS GOT TO BE the coolest IDE I've seen and use.  Lighttable has this killer feature where it cross a REPL with a source editor giving you the feel that you are editing running code. It also has this notion that a file is not the smallest unit of organization but a function is. Did I mention that it's free?

    Lighttable

  4. Netbeans 8. Aside from being free, Netbeans has got to have the some of the best toolsets for Java development found on a single IDE. It has wizards for all of Java world's coolest libraries like Hibernate, Spring and Swing. It also has killer support for web technologies like AngularJS, HTML5, Less and SaSS. Aside from that, Netbeans also has built in support of workflow units like Maven, Git and Mercurial. It also has a pretty lively plugin ecosystem making able to support other languages not just Java like Ruby with Rails.

    Netbeans

Thursday, March 13, 2014

Google drive docs with signatures

The Easy Way to add signatures into Google docs
I have stopped sending paper proposals to clients. It's too much of a hassle and often times not worth the cost. It's also worth mentioning not wholly environmentally friendly. So I try to mostly do stuff electronically and I also encourage my clients to do the same. I often tell them to adapt to the change or be left behind. Also, to make it sting a bit, I tell them that an IPad isn't just for playing (insert-what-bird-game-is-popular-here). But there are these unfortunate ones that just don't take an electronic proposal with a signature. These are the people who haven't really caught on but at least their are drifting in the right direction. All I can really do is accommodate them. Which leads me to: How do I put a digital signature on a Google Drive document?

There are two ways: The naive way and the easy way.

The Naive way
  1. Take a sheet of paper and make your signature using a wide pen (0.5mm pens at least)
  2. Scan it or take a picture of it
  3. Upload to Drive
  4. Insert it to document. 
The Easy way
  1. Create a new Google document
  2. Go to Insert > Drawing
  3. On the Drawing window, change the line to Scribble
  4. Save & Close
The easy way is not perfect though since signing with a mouse is like writing with a bar of soap but that can be easily fixed with writing tablet from CD-R King.

The naive way works also, it just too much work for me. Also, my phone camera takes potato-quality images and I don't have a scanner. Who has a scanner these days?

Wednesday, March 5, 2014

Whatever you do don't lose that Android keystore

What is Android keystore? A keystore is a used for signing Android apps so they can be published on the Play Store. How that Android app is made either native, hybird, whatever doesn't matter. You will still need that key.

To use a key store you need to do two things:
  1. Go to the AndroidManifest.xml file and change android:debuggable from "true" to "false". You then run a build
  2. Next is to sign the resulting APK (after running the build) with the javarsigner. The command should look something like:

    $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name
    
Now this assumes that you have created the keystore already if not then you have to go to your JDK folder and look for the keytool command.

$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

This will create a file that you must not lose under and circumstance. Do whatever it takes to keep it safe because if you lose then you won't be able to submit updates to your app.

Trust me on this, it's far less stressful keeping your keys safe than losing it. Can you imagine the hassle of having your users to re-install your Android app?

Monday, February 10, 2014

ElementaryOS, Netbeans 8 and that smexy new Terminal


So, I downloaded the Netbeans 8 which still in beta but I like it! Some of the new things I like are:

  1. The new smexy Terminal allowing me to run bower, grunt, yeoman commands without opening a separate Terminal - A BIG DEAL TO ME!
  2. New themes allowing for easier-on-the-eyes coding - ie. Less eye strain due to glare
  3. Better code hinting to JavaScript libs - although I only tried AngularJS
  4. Cordova or PhoneGap support
Now just for icing on the cake, I'm been running around with ElementaryOS which I advise people to try out especially that Microsoft was really really killing WindowsXP and you can't stand Windows 8. ElementaryOS is just a sweet mod to Ubuntu/Debian so it's pretty easy to install and use. And about that icing on the cake, Netbeans 8 "seems" to boot up and run faster on this relatively old Core2Duo 2GB machine. When I was running Win7 on it, it kinda felt sluggish.

Some tips if you're new to Netbeans and you're doing web development:
  1. Install the Emmet and Explore-from-here plugins
  2. Print out the Keyboard Shortcuts - Try out the Ctrl+Tab to navigate between view
Keep on coding.

Tuesday, January 21, 2014

Since ElementaryOS, I needed an alternative to SQL Server Manager

I've had ElementaryOS running on my office PC since November last year and I've enjoyed it immensely. There's nothing like trolling Mac users thinking their desktop environment is unique.

But since I'm on, by all accounts, a linux box how do I access the database and let's face it, most days in an office we devs don't write a lick of code but instead doing queries, mining data for reports. Special kind of reports. Sounds familiar? And this is where I needed an alternative to SQL Server Manager since my company is using SQL SERVER. Enter DBeaver.

DBeaver is billed as a free universal database manager. Although, it doesn't have all the bells and whistles of SQL Server Manager it's got enough that I get my job done and it's free. Let me repeat that: Free.

To install this, we're gonna go the apt-get route:

$ wget -c http://dbeaver.jkiss.org/files/dbeaver_2.3.5_amd64.deb
$ sudo dpkg -i dbeaver_2.3.5_amd64.deb
$ sudo apt-get install -f

I'm install the 64-bit version.

For the purist, you could always download the tarball and install it from the source.

$ wget -c http://dbeaver.jkiss.org/files/dbeaver-2.3.5-linux.gtk.x86_64.zip
$ tar xvf dbeaver-2.3.5-linux.gtk.x86_64.zip
$ make install

After the install what's left is to download the drivers which you can do in dbeaver.