Archive for May, 2011

Javascript: sort an array of json object by a property

Monday, May 30th, 2011
// a is the array to be sorted
function(a,propName){
		return a.sort(sortByFunc);
		function sortByFunc(a, b) {
			if (typeof a === "undefined") return -1;
			if (typeof b === "undefined") return 1;

		    var x = a[propName];
		    var y = b[propName];
		    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		}
}

iOS: WebKit Mobile Safari prevent bouncing/scrolling on touch move

Saturday, May 28th, 2011
$(function(){
   // WARNING: This seems to remove the 2 fingers scrolling on iOS WebKit
   $(document).bind("touchmove",function(event){
	event.preventDefault();
   });
});

Native application in HTML for iOS WebKit

postgresql: Set the default schema name (like using or use)

Saturday, May 21st, 2011
SET search_path TO myschema;

Java: C3P0 Maven (and hibernate c3p0 maven) and quick start

Saturday, May 21st, 2011
<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:postgresql://localhost/testdb" );
cpds.setUser("swaldman");
cpds.setPassword("test-password");

// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);

// The DataSource cpds is now a fully configured and usable pooled DataSource

...

Cleaning up on app shutdown

DataSources.destroy( cpds );

c3p0 Doc

For Hibernate, the maven dist is

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-c3p0</artifactId>
  <version>3.5.1-Final</version>
</dependency>

Java: slf4j log factory initialization

Saturday, May 21st, 2011
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(AnyClass.class);

HTML5: iOS like spinning wheel in HTML5/CSS3

Friday, May 20th, 2011

iOS Spinning Wheel in HTML5/CSS
http://cubiq.org/spinning-wheel-on-webkit-for-iphone-ipod-touch

Phonegap: Install / Uninstall Notes / Instructions for Mac

Sunday, May 15th, 2011
This installer will only install items under your home folder (signified by ~)

Items that will be installed:
(1) Xcode global var in ~/Library/Preferences/com.apple.Xcode.plist (which will be listed under Xcode Preferences -> Source Trees)
(2) PhoneGap Xcode static library and static framework project under ~/Documents/PhoneGapLib
(3) Xcode 3 project template in ~/Library/Developer/Xcode/Project Templates/PhoneGap
(4) Xcode 4 project template in ~/Library/Application Support/Developer/Shared/Xcode/Templates/Project Templates/Application
(5) PhoneGap Xcode static framework under /Users/Shared/PhoneGap/Frameworks/PhoneGap.framework (may change in future updates)
(6) Symlink to the framework in (5) under ~/Library/Frameworks

To uninstall:
(1) Remove the PHONEGAPLIB value in Xcode Preferences -> Source Trees
(2) Delete the ~/Documents/PhoneGapLib folder
(3) Delete the ~/Library/Application Support/Developer/Shared/Xcode/Project Templates/PhoneGap folder
(4) Delete the "~/Library/Application Support/Developer/Shared/Xcode/Templates/Project Templates/Application/PhoneGap-based Application.xctemplate" folder
(5) Delete the /Users/Shared/PhoneGap/Frameworks/PhoneGap.framework folder
(6) Delete the ~/Library/Frameworks/PhoneGap.framework symlink

If creating a new app does not copy the www folder, it can be found here (on Mac)

/Users/Shared/PhoneGap/Frameworks/PhoneGap.framework

See Also

PhoneGap for iOS xCode4 with No Template Tutorial

PhoneGap iOS xCode4 Template version

Install Phonegap Plugins (i.e. ChildBrowser)

PhoneGap Plugins Compiles error, no file, solution

Linux: Resize (extend) a Logical Disk in a Xen from DOM0

Saturday, May 14th, 2011

Assuming you have set your xen VM (e.g. domu1) points to a logical volume.

from DOM0

Extending the domu1 logical volume to 40G

lvextend -L40G /dev/vg0/domu1

from domu1

Resize the Physical Disk

pvresize /dev/hda

Resize the desired LV

lvextend -L15G /dev/vg0u/store
// might want to unmount the volume first, but this works on ext3 on live disk
resize2fs /dev/vg0u/store

See also

LVM Guide