Friday, June 29, 2012

MySQL: Improving LOAD DATA Performance

This is for InnoDB.

First, the following settings help:

innodb_buffer_pool_size = 4096M
innodb_doublewrite = 0
log-bin = 0
innodb_support_xa = 0
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 0

The other thing is to minimize the creation of indexes during loading. They can be created later if necessary.


Thursday, June 28, 2012

Spring: Bootstrapping From Webapp

This is how a Spring application is bootstrapped.

In web.xml, define the Spring context listener, so it will run when the app context is up, and also use the config file as defined in the <context-param> below:

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/configFileName.xml</param-value>
</context-param>

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Wednesday, June 27, 2012

Ant: Create File With Contents

This is how to create a file with content specified in the build.xml file:

<echo file="${filename}" append="true">
   <![CDATA[the contents of the file]]>
</echo>

Wednesday, June 20, 2012

Android Debug Log Squelched In Runtime?

It says in the API docs that "Debug logs are compiled in but stripped at runtime", so we don't have to be concerned about disabling debug prior to release?

http://developer.android.com/reference/android/util/Log.html

Monday, June 18, 2012

Linux Remote XWindows

To do it, go into X Windows on your client machine, just ssh into the box you wish with the option "-X" or "-Y" e.g.
ssh -X 192.168.2.2


And then start any GUI program from the command line e.g.
firefox &


And the program runs within a window on your desktop.

VirtualBox: VRDP Gotcha

VRDP allows usage of the RDP protocol to gain GUI access to a VM via the host. Although this feature shows up in the UI, it doesn't work until you install the extension pack. If you're a commercial user, then you're out of luck unless you're willing to buy a license, because the extension pack is only free for personal use and evaluation.

VirtualBox: Shutdown Virtual Machine From Command Line


VBoxManage controlvm "Test Server" poweroff

VirtualBox: Start Virtual Machine from Command Line in Headless Mode

Here's how it's done:

VBoxHeadless --startvm "Test Server" --vrde=off

The "vrde" option is for disabled VRDP access, for VMs where you do not need it (e.g. Linux where you can just use SSH).

Sunday, June 17, 2012

Java: Short to Bytes

Here's how to do it:


public static byte[] shortToBytes(short theShort) {
   byte[] theBytes = new byte[2];
   theBytes[0] = (byte)((theShort >> 8) & 255);
   theBytes[1] = (byte)(theShort & 255);

   return theBytes;
}

The purpose of the "& 255" bitwise operator is to ensure that all bits before the last byte are 0.

Java: Bytes to Short

Here is how to convert bytes to short in Java, with a function to prove/test it:


private static short bytesToShort(byte[] theBytes) {
   short msb = theBytes[0];
   short lsb = (short)(theBytes[1] & 255);
   msb = (short)(msb << 8);
       
   short result = (short)(msb | lsb);
   return result;
}
// for testing the bytesToShort functionpublic static void main(String[] args) throws Exception {
   int numValues = Short.MAX_VALUE - Short.MIN_VALUE + 1;
   short[] testValues = new short[numValues];
   for (int i = 0; i < testValues.length; i++) {
       testValues[i] = (short)(Short.MIN_VALUE + i);
   }
   int numWrongAnswers = 0;
   for (int i = 0; i < testValues.length; i++) {
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       DataOutputStream dos = new DataOutputStream(bos);
       dos.writeShort(testValues[i]);
       byte[] theBytes = bos.toByteArray();
       short s = bytesToShort(theBytes);

       String correct = "";
       if(s == testValues[i]){
               correct = "yes";
       }
       else {
               numWrongAnswers++;
               correct = "NO!!!!!!!!!!!";
       }
       System.out.println("original: " + testValues[i] + " converted: " + s + " OK? " + correct);
       }
       System.out.println("numWrongAnswers: " + numWrongAnswers);
}

Friday, June 15, 2012

iOS: Get Version Number of App

Do this:

NSString *lcVersionNumber = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];


Link: http://dipinkrishna.com/blog/2012/06/ios-apps-version-number-cfbundleversion/

Git: Deleting Branches, Locally and Remotely

Remotely:
  • git push origin :branchname
Locally:
  • git branch -d branchname
  • git branch -D branchname (to force to push through some warnings)
References:

MySQL: Replication of DDLs

In MySQL, replication doesn't just replicate changes to the data within the tables. Changes to table structure, and in fact even dropping and creating of databases are replicated as well.

Tuesday, June 12, 2012

Java HMAC-SHA256

While MD5 or SHA256 can be used to verify the integrity of a transmitted file, it doesn't guarantee that the file came from an authorized source. One way to do it is to use HMAC-SHA256 to create a signed hash. It uses a symmetric key approach where both sides are in possession of an identical key.

To verify that the file is signed by the same key, just sign the payload with the HMAC-SHA256 algorithm and the key, and then verify that the outputs are the same.

Java provides this functionality out-of-the-box in the javax.crypto package.

Code Sample:

byte[] payload = <the payload to sign>;
byte[] signatureBytes = <the sent signature>;
String key = "XXXXXXXXXXXXXX";
Mac hmacSha256 = Mac.getInstance("HmacSHA256");
byte[] keyBytes = key.getBytes("US-ASCII");
SecretKey secretKey = new SecretKeySpec(keyBytes,hmacSha256.getAlgorithm());

hmacSha256.init(secretKey);
hmacSha256.update(payload);

byte[] signedPayload = hmacSha256.doFinal();

boolean result = Arrays.equals(signedPayload, signatureBytes);

Monday, June 11, 2012

MySQL: Dumping a DB with Create DB Statement

Use the -B option e.g.

mysqldump -u username -p -B --result-file=filename.sql dbname

Note: You may run into this "gotcha" while restoring:
http://rstechjournal.blogspot.sg/2012/05/mysql-gotcha-after-restoring-database.html

Sunday, June 10, 2012

Base64: "=" Signs At The End

Base64 strings come in blocks of 4 (i.e. 3 bytes encoded into a 4 byte string) so any incomplete blocks (e.g. due to 1 byte remaining at the source) will have to be padded. The "=" serves as the padding.

iOS: Uploading App "No Suitable Application Records Were Found" Gotcha

After defining the app, the status is "Prepare for Upload". At this point, it is not possible to upload yet. You'll also need click on the "Upload Binary" link, answer a question on encryption, and then the status changes to "Waiting for Upload". At this point, you can upload.

iOS: App Store Review Times Crowdsourced

Link: http://reviewtimes.shinydevelopment.com/

Times are crowd-sourced from Twitter.

Saturday, June 9, 2012

Tagging in Git

To view tags:
- git tag

To add a tag:
- git -a tag vX.X

To delete a tag:
- git tag -d vX.X

Note that this only operates on your local repository, and is not pushed to the remote repository during a normal "git push" operation.

To push your tags to the remote repository as well:
- git push --tags

Tuesday, June 5, 2012

iOS: Switch Off NSLog Easily

I've tried doing this by implementing a new logging method but for some reason it just didn't work.

In the end, the only solution that worked (and was easiest to implement) is to use a macro to define a function e.g. DLog, and then using DLog throughout the app.

In this way, we just need to change the value of a pre-processor flag to switch NSLog on or off.

Example taken from one of the Stack Overflow answers:

#ifdef DEBUG_MODE
#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif


References:

iOS: Amount of RAM in Devices

Here's a good source: http://stackoverflow.com/questions/371107/how-much-ram-is-there-in-an-an-ios-iphone-ipad-ipod-touch-device

iOS: How Does Child View Knows It Has Been Popped In UINavigationController

Using viewDidUnload doesn't always work because sometimes we retain the a reference to the controller.

Instead, override the viewWillDisappear method

iOS: App Icons

They are implemented to naming conventions.

The app will look for a file named "Icon.png" and use it for the icon. You can also provide alternatives for the various screensizes.

More in this page: http://developer.apple.com/library/ios/#qa/qa1686/_index.html

iOS: Stack Size Limit

In the iOS, there is currently a limit of 1MB stack size on the main thread and 512KB stack size on a secondary thread.

The most significant thing about this limit is that primitive arrays are put on the stack if they are declared like this:
char carr[size];
int iarr[size];

If you have more than 512KB of them at a time on a secondary thread, you will get an error.

The solution is to allocate arrays on the heap using malloc e.g.:
char *byteBuffer = malloc(1000000);

You'll have to call "free(byteBuffer)" after you're done with it to release the allocated memory. Note that if you're using ARC, ARC does not do it for you. If it's an instance variable, you'll have to override the dealloc method of the object that owns the array, and free it in the dealloc method.

If it's an array that won't change very much, it's usually OK to just use NSData or NSMutableData. However if it's an array that will change very much, then you have to use malloc.

References

Monday, June 4, 2012

iOS: Simple Popup Form

To do this, use the UIAlertView. It is possible to add text input fields to it.

Note: the "\n\n\n" in the "message" parameter is used to create space for the text input fields.

References:

iOS: Making a POST Request

Performing a POST request in iOS is not that straightforward. Some have recommended using libraries such as ASIHTTPRequest, though it's no longer being worked on by the original creator.

Set HTTP Method

Using the NSURLRequest class, the default request type is GET. To change to POST:
  1. You need to first ensure that you are using NSMutableURLRequest, otherwise you can't even change it from GET to POST.
  2. Then set "HTTPMethod" to POST i.e. (urlReq.HTTPMethod = @"POST";)

Encoding POST Parameters

Next, the POST body needs to be created in a few steps. Firstly, the content of each parameter needs to be encoded in the Form-URL encoding format.

NSString provides a method "stringByAddingPercentEscapesUsingEncoding", but it's been reported that it creates output that won't be acceptable to web-servers. The solution is to call the "CFURLCreateStringByAddingPercentEscapes" function.

NSString *encodedString = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)sourceString, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", kCFStringEncodingISOLatin1);

Note the "__bridge" is needed if you use ARC.

References for this

Create the name/value pairs, and obtain the NSData format, here's an example for one parameter:

NSString *postBody = [NSString stringWithFormat:@"var1=%@",encodedString];
NSData *postBodyData = [postBody dataUsingEncoding:NSASCIIStringEncoding];
urlRequest.HTTPBody = postBodyData;

Notes

Some examples have also included setting headers such as Content-Length and Content-Type. It worked for me without them, but it could be just with the server I was working with.

References

iOS: NSDate to Unix Timestamp (long) Format and Back

Getting current time

NSDate *now = [NSDate date];

Getting long from NSDate

long long nowAsLong = [now timeIntervalSince1970];

Getting NSDate from long


long long timestamp = xxxxxxx;
// in the API, the time interval is in seconds, not milliseconds
NSTimeInterval timeInterval = (double)(timestamp/1000);

NSDate *theDate = [[NSDate alloc]initWithTimeIntervalSince1970: timeInterval];

Sunday, June 3, 2012

iOS: NSString to and from Binary Data

From Binary to String

If binary data is in NSData:
NSString *theStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];

If it is in a char[]:
NSString * theStr =[[NSString alloc] initWithBytes:theBytes length:numBytes encoding:NSUTF8StringEncoding];

From String to Binary

NSData *theData = [theStr dataUsingEncoding:NSUTF8StringEncoding];


References

iOS: Focus on Text Field and Open Keyboard

This can be done by calling the "becomeFirstResponder" method of the UITextField object.

i.e.
    [titleTextField becomeFirstResponder];

This will make the cursor focus on the text field and also bring up the keyboard (automatic and without user intervention).

iOS: Boolean Confusion

There is BOOL, bool, and Boolean, and then there is YES/NO, true/false, and TRUE/FALSE.

For Objective C, use BOOL and YES/NO. The rest are probably for compatibility with C code. Most of the time they seem to be usable interchangeably though, but just to be on the safe side, stick to what Objective C defines.

References:

iOS: Modifying Cell Height of UITableViewCell

To do this, override the "heightForRowAtIndexPath" method in the delegate and return the desired value. A hard-coded one will suffice if you want the same height for all rows. Otherwise, you can do the necessary calculations here and return the appropriate dynamic height.

iOS: Equivalent of ListView

It's UITableView:

References:

iOS: Running Some Code on Main UI Thread

dispatch_async(dispatch_get_main_queue(), ^{
  // do something here
});

Reference: http://stackoverflow.com/questions/5606145/objective-c-calling-a-method-on-the-main-thread

iOS: Null Evaluation Gotcha

Some APIs (e.g TouchJSON) return NSNull (which is an object) instead of "nil" when there are no results.

The usual null evaluation (varname == nil) will not evaluate to true.

You will have to additionally evaluate for ([varname isKindOfClass:[NSNull class]]) as well.

iOS: Easy Way to Download an Image From a Link

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:@"http://www.xxxxxxxx.com/image.png"]];

Only caveat is that this takes place synchronously, which is bad in most cases. If you're in the UI thread, you might want to do this in a separate thread, or use the NSURLConnection API.

Saturday, June 2, 2012

Making HTTP Requests From iOS

This blog post contains a good example:
http://agilewarrior.wordpress.com/2012/02/01/how-to-make-http-request-from-iphone-and-parse-json-result/

iOS Date Formatting

If you've obtained the date as a long, then create a NSDate object in this way:


        NSTimeInterval interval = (double)dateInLong;
        NSDate *theDate = [[NSDate alloc]initWithTimeIntervalSince1970: interval];


Then, create a date formatter:


        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"MMM' 'dd','yyyy' 'h':'mm':'ss' 'a"];
        NSString *theDateStr = [dateFormatter stringFromDate: theDate];

Date format:
MMM: Short form of month spelt out (e.g. Jan, Feb, Mar)
dd: Day, with 0 in front if less than 10
yyyy: Year (4 digit)
h: Hour, without 0 in front if less than 10
mm: minute
ss: second
a: AM/PM

iOS: API for JSON Parsing

TouchJSON is a simple and easy to use API for JSON parsing.

https://github.com/TouchCode/TouchJSON

Only "gotcha" is that the documentation suggested that it could deserialize a JSON string into object. That only applies to classes wrapping primitives (i.e. NSNumber, NSString etc.). If you had created an object and expect the library to auto-instantiate and populate the members of the object for you, TouchJSON isn't going to do it.

So if you have a complex object (which most of us do), just use the NSDictionary option.

Otherwise it works well.

Friday, June 1, 2012

Git: Diff Summarizing List of Changed Files Only

If you just wanted to see a list of changed files rather than the changes themselves from a remote repository:

git diff --name-status  master..origin/master

Reference: http://stackoverflow.com/questions/1607337/git-changed-file-summary-like-svn-diff-summarize-svn-status-from-console-no

Git: Specifying Private Key to Use for Git

In the ~/.ssh/config file, add the following lines:

Host gh
        Hostname github.com
        User git
        IdentityFile ~/.ssh/xxxx_rsa

Reference: http://superuser.com/questions/232373/tell-git-which-private-key-to-use

MySQL Show Process List

Inside MySQL Console:

SHOW PROCESSLIST

Reference: http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html

iOS: Getting the Current URL of the UIWebView

webView.request.mainDocumentURL;

Reference: http://stackoverflow.com/questions/2491410/get-current-url-of-uiwebview

SSHD Listen to Multiple Ports

This can be done in the SSHD config file.

Just have one line per port e.g.

Port 22
Port 80
Port 12345

References


MySQL Gotcha After Restoring Database

The user permissions may not be active until you call "Flush Privileges".

Sometimes, you may even have to drop the user and re-create it.

Fedora LVM Management

The default Fedora installation decides the disk partitioning for you. However, it uses LVM so changing that is relatively easy, the only issue being the volume has to be unmounted in the first place for you to work with it.

So the way to do it is:
  1. Boot the Live CD
  2. yum install system-config-lvm
  3. Run the program, and use it to re-allocate the volume sizes

MySQL Optimize Tables

This is similar to vacuum in PostgreSQL. While MySQL knows to recycle disk space for rows when inserting new data, if the table has been considerably reduced in size, then optimize should be run.

E.g.
OPTIMIZE TABLE tableName1,tableName2;

Reference: http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

iOS AudioQueue: Click sound between buffers


It only happens when a buffer is being enqueued, and it was because I only buffered one buffer before I started to play.

I had assumed that the AudioQueue will call the callback to let me populate the other buffer before the first buffer finished playing.

Instead, AudioQueue only does that after the first buffer finished playing. The click is due to a split-second buffer underrun while the buffer was being refilled.

The solution was to buffer more than one buffer before I start to play.

Reference: http://stackoverflow.com/questions/2564830/audioqueue-ate-my-buffer-first-15-milliseconds-of-it

Git: Discarding Changes in Working Directory

To discard changes to files in the working directory and reverting back to the file that was committed:

git checkout -- <filename>

Setting Up Git Server

In Linux, just install using the appropriate package manager.

In CentOS: yum install git
  1. Create the user account, setup public key authentication, and then login as the user
  2. Create a folder for repositories e.g. mkdir repo
  3. Create a folder for the repository you want to add: e.g. mkdir project.git
  4. Go into the folder, and run "git init --bare"
This is all that's needed on the server.

On the client from which to share the code:
  1. Create a repository i.e. git init
  2. Add and commit some files
  3. Setup remote e.g. "git remote add origin username@serveraddr:repo/project.git"
  4. git push origin master
References

Git: Creating a New Branch and Sharing It

git branch new_branch_name

git checkout new_branch_name

At this point, even if there are uncommitted files in the working directory, they won't be changed. They can then be committed into the branch.

To publish to remote:
git push -u origin new_branch_name

Other users:
git fetch
git checkout new_branch_name

Visualing Git Diffs

One of the biggest difficulties using the Git command line is visualizing diffs. Turns out there's already a built-in solution.

Just use "git difftool" instead of "git diff", it will launch a diff visualization program.

"git difftool -y <filename>"

The "-y" flag is to prevent a prompt from showing.

Passing Object Pointers Between Objective C and C under ARC

Under ARC (Automatic Reference Counting), there are some things to note when passing pointers between Objective C and C codes.

When passing Objective C object pointer to C function:
    void* cptr = (__bridge void*)objcptr;

And back
    ObjCClass *objcptr = (__bridge ObjCClass*)cptr;

References

iOS: Quitting the App

Now with multi-tasking, apps go into suspend mode when user presses the "Home" button. Apparently, Apple does not allow "exit(0)" to be used (some say it's OK to call it when the app enters background).

So either:
  1. The app never quits by itself
  2. Or configure it such that it never suspends (info.plist "Application does not run in background" ==> TRUE)
  3. Call "exit(0)" when app in background i.e. "applicationDidEnterBackground" callback
References

Print Hex in Objective C

Use the "%x" format

Note: convert to "unsigned char" first.

Link: http://stackoverflow.com/questions/5473896/objective-c-converting-an-integer-to-a-hex-value

Increasing Size of EBS Volume for Windows Server on EC2

Steps are similar to Linux server except the part where the OS FS has to be extended.

Link: http://www.foreachyield.com/post/2010/12/11/How-to-resize-an-EC2-Windows-Instance-EBS-Root-Device.aspx

XCode Breaking Compatibility With Old iOS Devices

Using XCode 4.3.2, it was not possible to install an iOS app into a 2nd Generation iPod Touch running iOS 4.2.1. What's worse is that there are no error messages indicating the cause of the problem.

The reason is that backward compatibility had been deliberately broken. It had to be added back in by adding support for armv6 devices and removal of device capability requirements from the info.plist file.

References

Objective C: NULL vs Nil

NULL: For C objects null pointers
Nil: For Objective C objects null pointers

But it seems they can be used interchangeably.

References

Objective C: #import vs @class

#import: import the headers
@class: tell the compiler to trust that the class exists in the header and will be imported by the implementation (*.m) file

Reference: http://stackoverflow.com/questions/322597/class-vs-import

MySQL: Convert String to Date

E.g. SELECT STR_TO_DATE('10-12-2012','%d-%m-%Y');

Reference: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

C: "memcpy" With Offset

Reference: http://forums.devshed.com/c-programming-42/can-you-memcpy-with-an-offset-285227.html

While there is no "offset" parameter, you can achieve the same effect by passing in the address of the xth element of the array.

It's About Customers' Needs, Not Your Products

Article: http://www.forbes.com/sites/mikemyatt/2012/05/01/to-increase-revenue-stop-selling/

Mac OS Add Folders to Paths

This was observed on Lion but not sure if it's available in earlier versions, but it's possible to add folders to the Mac OS shell search path by adding files into the /etc/paths.d folder.

Simply create a text file with the path to the folder you want to add as the contents of the file.

Mac OS Purge Inactive Memory

In Mac OS, memory classified as "Inactive" is memory used by recently quit applications. The idea is that these applications can later be relaunched very quickly. As such, it also takes some time to be released into "Free" memory.

The purge command (which can be run from Terminal), will immediately purge this memory from "Inactive" to "Free"

References:

EXC_BAD_ACCESS Gotcha with Interface Builder

This can happen when the Controller object referenced by the Nib has been released. In order to ensure that this doesn't happen, you'll need to keep it in memory e.g. by assigning it to a property in the AppDelegate class.

Apache Unable to Read Files Unless SELinux Context is Set Correctly

If you're getting a "permission denied" error when Apache tries to read and serve out a file, even though the file-system permissions are correct, then it's most likely due to the SELinux context issue.

For Apache to be able to read the file, the file needs to have SELinux context something like "system_u:object_r:httpd_sys_content_t:s0"

To find out the current SELinux context of files, "ls -alZ"

To change the SELinux context of a file:
chcon <Context> <File>
e.g. chcon system_u:object_r:httpd_sys_content_t:s0 index.html

PHP Unable to Connect to MySQL

When you get an error something like "SQLSTATE[HY000] [2003] Can't connect to MySQL server" with a subsequent error code "13" later on in the error message....

This is due to selinux preventing the web server from making external network connections.

To fix this, issue the following command as root:
setsebool -P httpd_can_network_connect=1

WAV File Format

Reference: http://www.sonicspot.com/guide/wavefiles.html

Note that numbers are in Little Endian format.

Calculating PCM Duration From Size

First step is to calculate the number of samples. This would be:

numSamples: number of samples
numBytes: size of data in bytes
numChannels: number of channels e.g. 1 for mono, 2 for stereo
numBytesPerSample: number of bytes per sample e.g. 1 for PCM 8-bit, 2 for PCM 16-bit
sampleRate: the sample rate of the PCM

numSamples = (numBytes / numChannels) / numBytesPerSample

Duration (milliseconds) = (numSamples * 1000) / sampleRate

Pentaho Data Types

Link: http://wiki.pentaho.com/display/EAI/User+Defined+Java+Expression

Amazon CloudFront Cache Invalidation

By default, the expiration time of files in the edge locations is 1 day. In order to reduce that, the "Cache Control" header can be used. In the case where the content origin is S3, the "Cache Control" header is set via the Metadata section, where the key is "Cache-Control" and the content is something like "public,max-age=600" where max-age is the expiration time in seconds.

Find Out Whether Apache Using PreFork or Worker

Use the command:
/usr/sbin/apache2 -l

Note: adjust accordingly for distros that use "httpd" instead e.g. Redhat based ones

Linux: Number of Open Files for Session

Query hard limit: ulimit -Hn
Query soft limit: ulimit -Sn
Set limit: ulimit -n <new limit>

You may or may not need to edit /etc/security/limits.conf before that

Note that there is also a separate system-wide setting in "/proc/sys/fs/file-max"

Linux: Query Number of Open Files Per Process

lsof -p <process id> | wc -l

Embeddable REST HTTP Server With Jersey and Grizzly

With Jersey and Grizzly, it's possible to have a lightweight embedded REST HTTP server in just a few simple steps. You can use this to add REST API capabilities to your own socket servers.

Reference: http://jersey.java.net/nonav/documentation/latest/user-guide.html#getting-started

Executable JAR Classpath Gotcha

When you use "java -jar" to run an executable JAR file, the CLASSPATH environment variable and the "-cp" parameter doesn't take effect. Instead, you have to put the classpath inside the manifest file, such that the manifest file has the following lines:

Main-Class: com.xxx.xxx.Main
Class-Path: abc.jar xyz.jar

Amazon EC2 Instance Public IP Address

Every Amazon EC2 instance has both a private and public IP address. Both are dynamic and subject to change. The only way to have a fixed IP is with Elastic IPs.

Note that the private and public addresses will change whenever the server is relaunched. However, it will not change when the server is merely rebooted.

The public IP address is not clear to the user because it never shows up in the console. To find out what the public IP address is, do a DNS lookup on the public DNS address field.

References:
http://support.rightscale.com/06-FAQs/FAQ_0160_-_Can_the_public_or_private_IP_addresses_change_on_an_EC2_instance%3F

Tool for Updating AWS Route 53 Entries

Route53 Fox: https://github.com/cookpad/r53-fox

It's a Firefox plugin. Compile the XPI and install it in Firefox.

Lets you modify Route53 entries without having to use EC2 Console. Just needs the Access ID and Secret Access Key.

Ubuntu Runlevel Gotcha

Usually, a Linux server (with no X Windows) will run at Runlevel 3. However, for Ubuntu, it treats Runlevels 2-5 the same.

Source: http://en.wikipedia.org/wiki/Runlevel