Nov 24, 2011

Cloud Foundry and Custom Domain

Posted Nov 24, 2011
Currently, Cloud Foundry (CF) doesn't support mapping of external URL's (See discussion).  The workaround is to use a reverse proxy. For this job, I hosted it Google App Engine (GAE) and used BS2 GAE Reverse Proxy. Credits to yufeiwu for the free reverse proxy app.

Prerequisite:
- Also, please read the Python Tutorial for the development environment and pushing your app to Google server.

Steps:
  1. Download the reverse proxy library (license: LGPL) in http://code.google.com/p/bs2grproxy/
  2. Modify bs2grpconfig.py
    • set TARGET_HOST to your cloud foundry url
      e.g. TARGET_HOST = "mvergel.cloudfoundry.com"
  3. Modify app.yaml
    • set your registered application id
  4. Push the app and make it live

I will continue to use this approach for my website until CF have a proper DNS support.

[UPDATE] Many are encountering a problem with the session using this method. There is a patch that fixes this issue. Thank you Marius Anton for the information.

Nov 23, 2011

Occupy the remaining height in CSS

Posted Nov 23, 2011

Today, I learned something new in CSS. The question is fairly simple: How do you occupy the rest of the height of a page?  Let's say you have a header with a height of 200px (the blue area above), and for the bottom part, you want the height to be flexible and fill-in the rest (red part). Same idea can be applied to widths.

Solution:
Use of absolute positioning. Specify the top style to be the height of your header and set bottom to 0.

Sample:

<!DOCTYPE html>
<html> <head> <title>Auto-expand body height</title> <style type="text/css"> body { height: 100%; margin: 0;
 position: relative;
}

html {
  height: 100%;
}

html * { 
  box-sizing: border-box;
-webkit-box-sizing: border-box; -moz-box-sizing: border-box; } </style> </head> <body> <div style="height: 200px; border: 1px solid blue;"> </div> <div style="border: 1px solid red; position: absolute; top: 200px; bottom: 0; width: 100%;"> </div> </body> </html>


[Updated June, 2014] Or if you want a fixed footer too:
<!DOCTYPE html>
<html>
<head>
<title>Auto Expand</title>
<style type="text/css">

body {
 height: 100%;
 margin: 0;
 min-height: 450px;
 position: relative;
}

html {
  height: 100%;
}

html * { 
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
}

</style>
</head>
<body>
  <div style="height: 200px; border: 1px solid blue;">
  </div>
  <div style="border: 1px solid red; position: absolute; top: 200px; bottom: 100px; width: 100%;">
  </div>
<div style="height: 100px; border: 1px solid green; position: absolute; bottom: 0; width: 100%;">
  </div>
</body>
</html>

Oct 19, 2011

Android 4.0 Ice Cream Sandwich is Now Available!

Posted Oct 19, 2011

This is exciting stuff! New features and API's, enhancements to existing ones, and a unified development for phones and tablets. You may want to check the highlights here

Oct 13, 2011

Fixing Errors in STS when Moving Grails Projects

Posted Oct 13, 2011

Problem
Did you transfer or check out your projects to another computer and found out that your projects contains errors due to missing plugins? The error is something like:
Project is missing required source folder: '.link_to_grails_plugins/...

Solution
Right click on the Project -> Grails Tools -> Refresh Dependencies

Oct 11, 2011

Dart: A new programming language from El Goog

Posted Oct 11, 2011

Google released a new web programming language called Dart. Still remember Go? I don't know that happened there, but maybe "Dart lang" will be the new "Go lang".

Google makes an effort to make it work both in client and server-side web programming which is a plus for any developer. Less languages to learn. It's about time, I think; Javascript is really getting old. I tried playing with Dart at http://try-dart-lang.appspot.com and it's very intuitive if you have a background in Javascript / Java / C++ / C#.

The ultimate goal of Dart is to replace Javsacript; feature-wise and performance-wise. I'm still skeptical about the idea  happening soon but maybe this is the future.  But instead of fighting to be the best, why not just co-exist happily?  I'll be happy either way.

If this language becomes mainstream, I'd want to be a part of a team or at least contribute to what they will do; which is hopefully a very good web framework inspired by Ruby on Rails or Grails.

If you're interested to discuss ideas with the Dart Team, here's a link to the Reddit discussion. Quite interestingly, read that Google has allocated significant resources on this project.

For more information, go to their website: http://www.dartlang.org

Sep 29, 2011

VMPlayer: Booting from USB Flashdisk

Posted Sep 29, 2011

Introduction
Booting from USB in VMPlayer turned out to be not as straightforward as I thought.  After some digging, found the solution in the article from The Holy Java article. Take note that this document does NOT teach you how to install Linux in a bootable USB; that's for another blog.

Solution
1. Download PLoP
2. Unzip the plpbtin.iso from plpbt-5.0.13/install to a folder
3. In VMPlayer, create new Virtual Machine and point the installer disc image file to the extracted plpbtin.iso
4. Run the VM and choose install all upon boot
5. Restart and choose USB when prompted with options

That's it! I was able to boot my Macpup 528 from my USB flash drive.

Issue(s) Encountered
1. USB was not detected
When you create your VM, there should be a USB in the hardware settings. By default if you choose Linux as your Guest Operating System and choose Other Linux 2.6 for the version, USB will be automatically detected. My mistake was to choose "Other" for the OS and Version which didn't include USB.

2. Still can't detect USB when booting
When you start the player, do the ff as shown in the image:
Virtual Machine -> Removable Devices -> Alcor Micro Mass Storage Device -> Connect

Sep 27, 2011

Using LGPL or Creative Commons (CC) License in Commercial Software

Posted Sep 27, 2011
Introduction
I'm working on a side project and I needed to find an existing software library that does something I need. I've got tons of options, the only problem is the license agreements. There are different types of licenses out there and it is imperative that we are aware about the agreement when we use 3rd party software in our applications.

Before we go to LGPL, a bit of GPL first. GNU General Public License (GPL) in simple terms states that should you decide to release or sell a program that includes a work or software with GPL, you should also release the source codea of your entire work and license them under GPL. It's worth noting that if you do not release your program, i.e. you use it privately or internally, you are not obligated to release your source codes publicly even if you include GPL'd libraries.

The viral nature of this license is a big turn off to the software corporations because of the potential loss of intellectual property. In my opinion, GPL is almost like a religion; for a person to advocate it, he/ she should truly believe in its goal with a bit of forcing others to do the same thing. It's not a bad thing though, but a bit idealistic. From GPL FAQ: The goal of the GPL is to grant everyone the freedom to copy, redistribute, understand, and modify a program. If you could incorporate GPL-covered software into a non-free system, it would have the effect of making the GPL-covered software non-free too.


For more information regarding GPL, you can read the entire document here.


LGPL
With the strict rules of GPL, LGPL aims to make it more "friendly" by adding "L" in LGPL which ironically means "Lesser".  The main difference between GPL and Lesser GPL is that it allows non-free applications to link with LGPL software without being forced to release the entire source code.

Specifically in web applications, it is easier to use LGPL because of the concept of libraries where you can just link them to your work without having to modify the existing GPL library. For client-side software like Javascript where files can be linked to HTML without the need to modify the 3rd party software. Likewise with server-side programming e.g. in Java libraries which are still separated from the main code.

Read the entire LGPL document here.

Creative Commons (CC)
CC is another type of license or licenses which basically differentiate itself with the focus on attribution.  You need to somehow attribute the author when you use his/ her work. For example when you create a website / application, it should be written somewhere that you used the author's work in order; this is to comply with the license agreement, although this can be bypassed with the consent of the author.

Read the different licenses under Creative Commons here.

Conclusion
It's still best to use MIT, BSD, and Apache licenses for commercial / closed source software.  It's free, free as in beer with no legal liabilities and nothing much to think about, but do consider giving donations when you find it useful. But when using other licenses such as LGPL and CC, it's not always straightforward. It's a case to case basis, other companies use LGPL software, others strictly avoid it.

When you're not sure, it's best to consult higher authority or a lawyer to avoid legal consequences. Personally as a Freelancer, I use LGPL when needed, but opt to MIT, BSD or Apache license when there's alternatives.

Sep 26, 2011

Ruby on Rails 3.1 Released!

Posted Sep 26, 2011
Last 30th of August, Ruby on Rails 3.1 has been released which includes whole new set of features. It's more like a version 4.0 in my opinion with the major changes incorporated. For more information on the changes,  read the Ruby on Rails blog article.

I'm still testing the waters With regards to this framework, and so far so good. Maybe this is a good time to invest time and energy in learning this new web framework. Big fan of Don't Repeat Yourself (DRY) and Convention over Configuration principles, which lead me to two new frameworks Ruby on Rails (RoR) and Grails (which is like Rails for Java).

Haven't used either frameworks in real-world applications but I have a client that's interested in using a new framework so I might recommend that we use one of them. If you're interested in these frameworks, I'd suggest you give it a try and download them in their respective websites:

Aug 5, 2011

Uninitialized constant Rake::DSL in Rails 3

Posted Aug 5, 2011

I got this error when I try to migrate a user model from Devise. The log says:
rake aborted!
uninitialized constant Rake::DSL
...[garbage logs]...

This problem is caused by an outdated Rake gem.   If you're rake version is less than 0.9.2 than you will experience this problem

To check Rake's version, execute this in the command line:
rake --version

You will say. But hey I just recently installed everything from Ruby to Rails gem. In my case, I got multiple installation of Rake, so I got 0.8.7 and 0.9.2 at the same time and my command line is using 0.8.7.

To be safe, I uninstalled all rake versions:
gem uninstall rake

If you have multiple versions of rake, it will ask you which version you'd like to uninstall

And install the latest again:
gem install rake

And voila! No more DSL problem when I execute
rake db:migrate

Speed-up Eclipse

Upon searching the web I cam accross several references to help improve the performance of Eclipse.

JVM Settings
For general case, you can change the JVM settings and edit your eclipse.ini
Reference: http://stackoverflow.com/questions/142357/what-are-the-best-jvm-settings-for-eclipse

-data
../../workspace
-showlocation
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
-vm
C:/Prog/Java/jdk1.6.0_21/jre/bin/server/jvm.dll
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Declipse.p2.unsignedPolicy=allow
-Xms128m
-Xmx384m
-Xss4m
-XX:PermSize=128m
-XX:MaxPermSize=384m
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-XX:+CMSIncrementalPacing
-XX:+UnlockExperimentalVMOptions
-XX:+UseG1GC
-XX:+UseFastAccessorMethods
-Dcom.sun.management.jmxremote
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=C:/Prog/Java/eclipse_addons

For more information on the details of the parameters, check out the reference.


http://stackoverflow.com/questions/316265/tricks-to-speed-up-eclipse also suggested to use the latest version of Eclipse and Java to improve performance.  As of writing, I'm using Eclipse 3.6 Helios and JDK 1.6.0_22.  I'm yet to update because it will take time to install the new versions, but I'm very much happy with the JVM settings.


Improve Eclipse Autocompletion

Sometimes, I experience a slow response from Eclipse when it triggers the auto-complete especially the Java Autocomplete feature. For Java, you can go to Eclise Preferences -> Java -> Editor -> Content Assist -> Advanced and you can remove the default proposals you are not using (first table).  For my case, I unchecked all except for "Java Proposals" and "Template Proposals".  For the second table, you may be wondering what content assist cycling is, this is activated when you press Ctrl+Space more than once and the content assist cycles to different proposals.  You can just uncheck all if you are not using content assist cycles.

The next thing is not really to improvement performance, but more of a preference or a setting.  You can increase / decrease the activation delay of you content assist's auto-activation feature.  This normally happens after you put a dot (.) and Eclipse tries to find proposals that suites your programmign needs.  If you go to Eclise Preferences -> Java -> Editor -> Content Assist and change the value to your liking. By default, the setting is 200 (in milliseconds), I prefer to use 0. Note though for slower computers, setting it to 0 might degrade the performance and actually slow down your coding.

--
Search Keywords:
  • eclipse speedup
  • eclipse speed up
  • speed up eclipse
  • java options eclipse performance

Aug 2, 2011

Alfresco Java Perm Gen Space Error

Posted Aug 2, 2011
As advised by Alfresco JVM Tuning, you can try to increase your max perm gen to 256M if you are encountering perm gen error (out of memory).
Modify or add this to your JVM Parameter / Settings:
-XX:MaxPermSize=256M

If you still observe this error after some time, it is possible that there is a memory leak somewhere that's causing this and you need to find where the leak happens.

Java 7 Has Finally Been Released

At long last, after 5 years of waiting and bureaucratism Java 7 is here! I still remember reading the Stackoverflow question: "Who is preventing the release of Java 1.7?" and was disappointed by Sun and Apache's dispute; reminds me of a failed democracy with too many people having a say, slowing the progress to a crawl.

Anyway, enough of ranting. Java 7 was released on July 28, 2011. It's also worth noting that this is the first Java release after Oracle bought Sun. This major release includes many new features including my favorite "strings in switch statements" and "try-with-resources statement". As a fan of Groovy language, I was excited by this release because it includes the much awaited JSR292 which aims to support the implementation of dynamically-typed languages promising significant performance gain. For more information about the implications of JSR292, read Baptiste Wicht's article.

For more information on the new features and enhancements, check out the release notes.  Java Development Kit (JDK) 7 is available for download here.

Jul 28, 2011

XCode and SVN - Unable to load revisions

Posted Jul 28, 2011
Introduction
There's a weird bug happening in XCode when I add a repository (File -> Source Control -> Repositories...).  I tried other credentials and I'm able to get the revisions, but every time I added mine, I just can't access the SVN even if I supplied the correct username and password. It just keeps telling me "Unable to load revisions"

I even tried removing and adding the repository and account details to no avail.  At first I thought my access was blocked turned out that XCode is using the wrong cache to authenticate itself.


The Solution (or rather workaround)
Go to Terminal and type:
svn checkout [svn_server_path] [local_path] --username [username]

E.g.
svn checkout svn://192.168.0.2/data/master/SVN/PROJ1/trunk/sample ./sampletemp --username mvergel

It will then ask for your password. Supply the correct one and continue to check out the contents.

After this process, your XCode repository should now be okay. If it's not, try to restart XCode.

Jul 20, 2011

How to make UILabel's text bold

Posted Jul 20, 2011
If you want to retain the system font and make it bold:

[myLabel setFont:[UIFont boldSystemFontOfSize:16]];

Jul 19, 2011

Automatic Comment Folding in Eclipse

Posted Jul 19, 2011
A good documentation is important for team development but code comments sometimes consumes a lot of vertical space and obstructs your view.

Fortunately Eclipse has a way to automatically fold or hide them.

Go to Preferences > Java > Editor > Folding

Check the ff:
  • Comments
  • Enable folding (default)
  • Header Comments (default)
  • Imports (default)