Tuesday, December 13, 2011

ubunut failed to boot - Grub2 recordfail FAIL

http://jwalanta.blogspot.com/2011/05/grub2-recordfail-fail.html

I have this headless, keyboardless server running on Ubuntu 10.04. Runs fine, but once in a while while there's power cut off the server still remains dead when the power is back. I connected monitor and keyboard and found that the problem is with Grub2.

Turns out there's a variable named recordfail which is set to 1 during next boot whenever there's some problem with the computer (like due to power failure).

Now if you see /boot/grub/grub.cfg file, it has the following lines:

if [ ${recordfail} = 1 ]; then
set timeout=-1
else
set timeout=10
fi
Which means, the timeout counter is disabled whenever the recordfail variable is set. This is nice for desktop environment, which has a monitor, so I can see the Grub countdown is disabled so I can proceed with Repair option if I have to, but for headless servers the computer just sits idle at Grub screen, puzzling the poor sysadmin.

Fix? I changed the timeout=-1 to timeout=10.

Sunday, December 11, 2011

Installing ubuntu 11.04 server via USBstick

The installer halts at "[!!] Detect and mount CD-ROM" - "Your installation CD-ROM couldn't be mounted. Try again to mount the CD-ROM? (Yes/No)"

1. When you get the error, Alt-F2 to a second console.
2. Find out which device your USB stick is (tail -n 100 /var/log/syslog)
3. Then mount it to /cdrom (mount -t vfat /dev/sd[abcd] /cdrom
4. Alt-F1 to get back to the install console, and try detecting again

***Make the startup USB disk writable when create it, it will be no such error after restart

Wednesday, June 29, 2011

How To Fix MySQL Error ‘Could not parse relay log event entry’

How To Fix MySQL Error ‘Could not parse relay log event entry’

1. STOP SLAVE

2. SHOW SLAVE STATUS

3. Note down ‘Relay_Master_Log_File’ and ‘Exec_Master_Log_Pos’ entries.

{
4. RESET SLAVE //Connection information stored in the master.info file is immediately reset using any values specified in the corresponding startup options. This information includes values such as master host, master port, master user, and master password

5. CHANGE MASTER TO ….. (use MASTER_LOG_FILE=relay_master_log_file and MASTER_LOG_POS=exec_master_log_pos from Step 3)
}
OR // without reset ??
{
CHANGE MASTER TO master_log_file=”mysql-bin.000020″, master_log_pos=5382560;
}

6. START SLAVE

Tuesday, May 31, 2011

How to post blackberry OTA files on your website!

When posting files on your website for OTA downloads, you will need to either modify the .htaccess file (for Linux servers) or MIME Types (for Windows servers.)

Linux & modifying the .htaccess file:
Place the following information into a notepad file named ".htaccess"

AddType text/vnd.sun.j2me.app-descriptor jad
AddType application/java-archive jar
AddType application/vnd.rim.cod cod


Windows & adding MIME Types:
Add the following information to the MIME Types on your host site

Extension: jad
MIME type: text/vnd.sun.j2me.app-descriptor

Extension: cod
MIME type: application/vnd.rim.cod

http://forums.crackberry.com/f3/how-post-ota-files-your-website-177967/

Wednesday, May 25, 2011

Mac sleep mode and freeze issue

From http://forums.macrumors.com/showthread.php?t=290091

I had the same freezing problems after closing the lid and going to sleep mode in my maxed up MacBook Pro (17" 2.93GHz Intel Core 2 Duo, 8GB 1067 MHz DDR3 RAM, 250GB OCZ Vertex SSD). Very annoying! Nonetheless, after googling a lot, I apparently solved this proble by changing the sleeping mode modality from "3" (default in the newest machines) to "0" (older modality).

Here is a more detailed explanation:

After you launch Terminal, the first step is to determine which sleep mode your Mac is currently using (in case you wish to go back to it). You can both view and change the sleep mode using the Unix program pmset. To see your current settings, type pmset -g | grep hibernatemode. You should see something like this:

pmset -g | grep hibernatemode hibernatemode 3

Great, so your machine is using mode 3, whatever that might be. Well, thanks to the documentation for the handy Deep Sleep Dashboard widget, which puts your machine immediately into hibernation mode (so you don’t have to yank all the power sources to invoke it), we can tell exactly which mode is which:

0 - Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
1 - Hibernation mode, with RAM contents written to disk, system totally shut down while “sleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
3 - The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.

To change your sleep mode, you use pmset again, providing the variable and value you wish to assign. So to return to the old style sleep mode (which is mode 0 from the above list), enter this command:

sudo pmset -a hibernatemode 0

Press Return, and you’ll be asked for your password. Provide it, and your sleep mode has been changed. Note that restarting is not required for these changes to take effect.

Recover some drive space
If your machine was previously set to mode 3 (or 7 ) and you’ve reverted to the old style sleep mode, you’ve got one more step to take: recover the drive space used up by the copy of your system’s RAM, which was created the last time you slept the machine prior to making the switch. In Terminal, enter these two commands, pressing Return after each and providing your password when asked (in my case it didn't ask for my password again after changing the sleep mode)

cd /var/vm
sudo rm sleepimage

In my case it released almost 8GB of disc space. I guess it will closely amount the amount of RAM your system has. Ironically, by trying to make a "super system" by paying $2,000 for 8GB RAM plus the SSD drive, it might have been to much RAM to copy and recover to the SSD every time the system goes to sleep and wakes up...as they say "the best is sometimes enemy of the good".

Good luck!

JR Mora

Tuesday, April 19, 2011

Ajax long connect using server heart beat to check client connect if it is closed

Using a trick HTTP response header

HTTP/1.1 200 OK
Server: xxx
Beat: Waiting.................................... // trick
Connection:Close
Content-length:255
Content-type:text/xml
Date:Wed Apr 20 12:01:17 EST 2011
Expires:Sun, 24 Apr 1981 01:29:32 GMT

Void Google Chrome pointer spinning for long Ajax connection

Put the request in a timer, or link, never directly put in page onload event

function onload() {
setTimeout(function() { // start ajax long connection in another thread to avoid google Chrome pointer spinning
doLongAjaxCallLoop ();
}, 3000);
}



Wednesday, March 2, 2011

how to create .ipa file for iPhone apps

Here is the process of creating ipa file from .app file.

Step 1: Create a folder named Payload anywhere in your computer.

Step 2: Build your app using AdHoc profile and then put .app file in this folder.

Step 3: Then compress the Payload folder in Zip format.

Step 4: Now you have to rename the .zip file into .ipa file.

Your .ipa file is ready. You can send the file along with AdHoc profile for testing.

Tuesday, March 1, 2011

Using xcconfig, abandoning the Build Panel in XCode

XCode provides a better solution called xcconfig files. Everything you can do in the build panel can be done in xcconfig files, and you can actually read them and make comments. So let’s make some.

  1. Create a new Window-Based iPhone Application. (Everything we do here works exactly the same for Mac.)
  2. Add a new group to your Groups & Files called “Build Configuration”.
  3. Add a new file to the group. Under “Other” select “Configuration Settings File.” Call it “Shared.xcconfig”.
  4. Create three more xcconfig files called Debug, Release and Application.
  5. Double-click the Project to open the Project Info panel, and select Build.
  6. Select Configuration: “Debug” and Show: “Settings Defined at This Level.”
  7. Select all the settings (you can use Cmd-A here).
  8. Copy them with Cmd-C.
  9. Go back to Debug.xcconfig and paste with Cmd-V. You now know how to find out the xcconfig syntax for any Build Panel setting you’re uncertain of.
  10. Go back to the Build Panel and hit Delete to set all settings to default. Select “Show: All Settings” so you can see your settings again.
  11. In the lower-right of the panel, for “Based On:” select “Debug.” You should see your old settings show back up, but not bold this time.
  12. Repeat for Configuration: “Release”. Copy them to Release.xcconfig and delete them from the Build Panel.
  13. Double-click on the Target, and repeat the process, moving both its Debug and Release settings to Application. Put in a comment to indicate which are the Debug settings and which are the Release settings. We’ll clean them up shortly. Select “Configuration: All Configurations” and “Based On: Application.”

We’ve now moved everything from the build panel to the xcconfig files, and the system should build. Debug and Release are slightly confused because we mixed the settings in Application, but we’ll fix that now.

Look in Application.xcconfig, and move anything that’s in Debug but not in Release to Debug.xcconfig, and anything in Release but not Debug to Release.xcconfig. Anything that’s in both, delete the second copy of.

Anything that is in both Release and Debug, move to Shared, and put #include "Shared.xcconfig" at the top of the Release and Debug configs.

If you’ve followed all the instructions, you should have four files that look like this (assuming your product’s name is “Test”):

Shared.xcconfig

ARCHS = $(ARCHS_STANDARD_32_BIT) SDKROOT = iphoneos2.2.1 CODE_SIGN_IDENTITY =  CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer PREBINDING = NO GCC_C_LANGUAGE_STANDARD = c99 GCC_WARN_ABOUT_RETURN_TYPE = YES GCC_WARN_UNUSED_VARIABLE = YES 

Release.xcconfig

include "Shared.xcconfig"

COPY_PHASE_STRIP = YES

Debug.xcconfig

include "Shared.xcconfig"

ONLY_ACTIVE_ARCH = YES COPY_PHASE_STRIP = NO GCC_DYNAMIC_NO_PIC = NO GCC_OPTIMIZATION_LEVEL = 0

Application.xcconfig

INFOPLIST_FILE = Info.plist PRODUCT_NAME = Test ALWAYS_SEARCH_USER_PATHS = NO GCC_PRECOMPILE_PREFIX_HEADER = YES GCC_PREFIX_HEADER = Test_Prefix.pch 

If you Build&Run now, everything should work. It’s not a great build configuration, but it’s Apple’s default in a form that we can start understanding and improving.

http://robnapier.net/blog/build-system-1-build-panel-360#more-360

Sunday, February 27, 2011

How to Extend Mac OS X 10.x Partition in Vmware Workstation

how to use unallocated space and merge it into another Mac OS X partition. Basically these are the steps to expand the main partition after increasing the size of a virtual machine running MAC OS X.

Thursday, February 24, 2011

Add labels to Google blogger by API

PHP:
http://gdatatips.blogspot.com/2008/07/labeling-blogger-posts.html

$label1 = new Zend_Gdata_App_Extension_Category(
'foo', 'http://www.blogger.com/atom/ns#');
$label2 = new Zend_Gdata_App_Extension_Category(
'bar', 'http://www.blogger.com/atom/ns#');
$entry->setCategory(array($label1, $label2));

Java:
http://www.one-minute-info.com/2010/06/add-label-to-posts-via-java-blogger-api.html

myEntry = new Entry();
myEntry.setTitle(new PlainTextConstruct("some title"));
myEntry.setContent(new HtmlTextConstruct("some HTML body"));

categories=myEntry.getCategories();

category= new Category();
category.setTerm("whatever label you like such as Google Blogger or Java API");
category.setLabel(null);
category.setScheme("http://www.blogger.com/atom/ns#");
category.setLabelLang(null);

categories.add(category);

URL postUrl = new URL("http://www.blogger.com/feeds/123456/posts/default");
myService.insert(postUrl, myEntry);

Wednesday, February 23, 2011

google data and blogger api

http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries
http://code.google.com/apis/blogger/docs/1.0/developers_guide_js.html

http://itcoding.blogspot.com/feeds/posts/default?alt=json-in-script&category=mobile

Wednesday, February 16, 2011

Build and Archive iOS apps by command line

http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/


#!/bin/sh

# build.sh
#
# Created by Vincent Daubry on 19/01/10.
# Copyright 2010 OCTO. All rights reserved.

PROJDIR=${WORKSPACE}/___PROJECT NAME___
PROJECT_NAME=___XCODE PROJECT NAME___
TARGET_SDK="iphonesimulator4.0"
PROJECT_BUILDDIR="${PROJDIR}/build/Release-iphoneos"
TARGET_TEST_NAME="UnitTests"
BUILD_HISTORY_DIR="/Users/barbu/Desktop"
DEVELOPPER_NAME="iPhone Developer: M VINCENT DAUBRY (J9TS3TJRYX)"
PROVISONNING_PROFILE = "/Users/barbu/Desktop/desire.mobileprovision"

# compile project
echo Building Project
cd "${PROJDIR}"
xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release

#Check if build succeeded
if [ $? != 0 ]
then
exit 1
fi

/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPPER_NAME}" --embed "${PROVISONNING_PROFILE}"

codebuild -target MyApp -configuration AppStore BUNDLE_VERSION=`date "+%y%m%d"`

Build iphone/iOS apps with java ant and xcodebuild


<project name="cc-build" default="build" basedir="checkout">
<target name="build">
<delete dir="MyCocoaApp" />
<cvs command="co MyCocoaApp" />
<exec executable="xcodebuild" dir="MyCocoaApp" failonerror="true">
<arg line="-target MyCocoaApp -buildstyle Deployment build" />
</exec>
</target>
</project>

https://github.com/phonegap/phonegap-iphone/blob/master/build.sh
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html

find your computer's neighbourhood ip address by one linux command

Run below line as one command in linux

for i in `seq 0 254`; do sudo arping -I eth0 -c1 -f 192.168.1.$i; done |grep Unicast

Wednesday, February 9, 2011

linux & mysql shell shorcut - good for mobile ssh

Key Sequence

Meaning

Up arrow or Ctrl-P

Recall previous line

Down arrow or Ctrl-N

Recall next line

Left arrow or Ctrl-B

Move cursor left (backward)

Right arrow or Ctrl-F

Move cursor right (forward)

Escape b

Move backward one word

Escape f

Move forward one word

Ctrl-A

Move cursor to beginning of line

Ctrl-E

Move cursor to end of line

Ctrl-D

Delete character under cursor, Ctrl-U Clear the line before cursor position

Delete

Delete character to left of cursor

Escape D

Delete word

Escape Backspace

Delete word to left of cursor

Ctrl-K

Erase everything from cursor to end of line

Ctrl-_

Undo last change; may be repeated

Ctrl + Z
Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + R Let’s you search through previously used commands
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + K Clear the line after the cursor

Friday, January 28, 2011

Java binary data process class DataInputStream

The good sample for binary data processing

Thursday, January 27, 2011

Search a byte array for a byte sequence

The Knuth-Morris-Pratt Pattern Matching Algorithm can be used to search a byte array.
http://helpdesk.objects.com.au/java/search-a-byte-array-for-a-byte-sequence

Thursday, January 20, 2011

Stanford Javascript Crypto Library

SJCL is secure. It uses the industry-standard AES algorithm at 128, 192 or 256 bits; the SHA256 hash function; the HMAC authentication code; the PBKDF2 password strengthener; and the CCM and OCB authenticated-encryption modes.

http://crypto.stanford.edu/sjcl/
https://github.com/bitwiseshiftleft/sjcl/tree/master/browserTest
http://bitwiseshiftleft.github.com/sjcl/demo/

Wednesday, January 19, 2011

BlackBerry webkit javascript touch events


var lastX=0;
var lastY=0;
document.ontouchstart = function(event) {
var touchEvent = event.changedTouches[0];
lastX = touchEvent.pageX;
lastY = touchEvent.pageY;
}

document.ontouchmove = function(event) {
event.preventDefault();
}

document.ontouchend = function(event) {
var touchEvent = event.changedTouches[0];
var deltaX = lastX - touchEvent.pageX;
var deltaY = lastY - touchEvent.pageY;
alert("deltaX: " + deltaX + " deltaY: " + deltaY);
}


For android and iPhone, it can be

startPoint.x = e.touches[0].pageX;
startPoint.y = e.touches[0].pageY;

General codes:

if(!e['touches']) e['touches'] = e.changedTouches;

startPoint.x = e.touches[0].pageX;
startPoint.y = e.touches[0].pageY;

Tuesday, January 18, 2011

blackberry security error: dom exception 18

blackberry phonegap error

security error: dom exception 18

Use the following steps to remove the database on the internal MMC.
1) Restart the device
2) Start Media application then select “Explore” in the Menu
3) Select “Show Hidden” in the Menu
4) Navigate to /Device/BlackBerry/system/appdata/rim
5) Delete the webstorage folder if there
6) Start your apps.