Nov 19, 2012

PostgreSQL, Rails and Heroku

rails new blog -d postgresql

Aug 7, 2012

The performance of SAMSUNG 830 Series 2.5-Inch 256GB on Mountain Lion

Here is the result from Xbench:


Results 565.10
System Info
Xbench Version 1.3
System Version 10.8 (12A269)
Physical RAM 8192 MB
Model MacBookPro8,2
Drive Type SAMSUNG SSD 830 Series
Disk Test 565.10
Sequential 374.59
Uncached Write 593.36 364.31 MB/sec [4K blocks]
Uncached Write 598.18 338.45 MB/sec [256K blocks]
Uncached Read 164.58 48.17 MB/sec [4K blocks]
Uncached Read 803.01 403.59 MB/sec [256K blocks]
Random 1149.93
Uncached Write 847.69 89.74 MB/sec [4K blocks]
Uncached Write 967.11 309.61 MB/sec [256K blocks]
Uncached Read 2547.83 18.05 MB/sec [4K blocks]
Uncached Read 1146.40 212.72 MB/sec [256K blocks]


After trim enabler:


Results 563.27
System Info
Xbench Version 1.3
System Version 10.8 (12A269)
Physical RAM 8192 MB
Model MacBookPro8,2
Drive Type SAMSUNG SSD 830 Series
Disk Test 563.27
Sequential 373.48
Uncached Write 583.23 358.09 MB/sec [4K blocks]
Uncached Write 596.24 337.35 MB/sec [256K blocks]
Uncached Read 164.58 48.17 MB/sec [4K blocks]
Uncached Read 804.85 404.51 MB/sec [256K blocks]
Random 1145.28
Uncached Write 1268.14 134.25 MB/sec [4K blocks]
Uncached Write 705.85 225.97 MB/sec [256K blocks]
Uncached Read 2562.21 18.16 MB/sec [4K blocks]
Uncached Read 1114.80 206.86 MB/sec [256K blocks]


Almost the same, as expected.

Apr 25, 2012

HOWTO: use pathogen to manage vim plugins

I am now using pathogen and GitHub to manage my vim plugins.
They are not difficult to use, but you need a few git commands to set it up, which I found very annoying.

To init .vim folder in Linux (or vimfiles for Windows), type:


mkdir .vim
cd .vim
git init
wget https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim -P ~/.vim/autoload
git add .
git commit -m 'initial commit'


To install each vim plugin, type: (here I use neocomplcache-snippets-complete as an example)


git submodule add https://github.com/Shougo/neocomplcache-snippets-complete.git bundle/neocomplacahe-snippets-complete
git add .gitmodules bundle/neocomplcache-snippets-complete
git submodule init



Apr 16, 2012

iOS errors


/* FoundationErrors.h
Copyright (c) 2004-2011, Apple Inc. All rights reserved.
*/

#import <Foundation/NSObject.h>

/* NSError codes in NSCocoaErrorDomain. Note that other frameworks (such as AppKit and CoreData) also provide additional NSCocoaErrorDomain error codes.
*/
enum {
    // File system and file I/O related errors, with NSFilePathErrorKey or NSURLErrorKey containing path or URL
    NSFileNoSuchFileError = 4,     // Attempt to do a file system operation on a non-existent file
    NSFileLockingError = 255,     // Couldn't get a lock on file
    NSFileReadUnknownError = 256,                           // Read error (reason unknown)
    NSFileReadNoPermissionError = 257,                      // Read error (permission problem)
    NSFileReadInvalidFileNameError = 258,                   // Read error (invalid file name)
    NSFileReadCorruptFileError = 259,                       // Read error (file corrupt, bad format, etc)
    NSFileReadNoSuchFileError = 260,                        // Read error (no such file)
    NSFileReadInapplicableStringEncodingError = 261,        // Read error (string encoding not applicable) also NSStringEncodingErrorKey
    NSFileReadUnsupportedSchemeError = 262,     // Read error (unsupported URL scheme)
#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    NSFileReadTooLargeError = 263,     // Read error (file too large)
    NSFileReadUnknownStringEncodingError = 264,     // Read error (string encoding of file contents could not be determined)
#endif /* MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED */
    NSFileWriteUnknownError = 512,     // Write error (reason unknown)
    NSFileWriteNoPermissionError = 513,                     // Write error (permission problem)
    NSFileWriteInvalidFileNameError = 514,                  // Write error (invalid file name)
#if MAC_OS_X_VERSION_10_7 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    NSFileWriteFileExistsError = 516,     // Write error (file exists)
#endif
    NSFileWriteInapplicableStringEncodingError = 517,       // Write error (string encoding not applicable) also NSStringEncodingErrorKey
    NSFileWriteUnsupportedSchemeError = 518,     // Write error (unsupported URL scheme)
    NSFileWriteOutOfSpaceError = 640,                       // Write error (out of disk space)
#if MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    NSFileWriteVolumeReadOnlyError = 642,     // Write error (readonly volume)
#endif

    // Other errors
    NSKeyValueValidationError = 1024,                       // KVC validation error
    NSFormattingError = 2048,                               // Formatting error
    NSUserCancelledError = 3072,     // User cancelled operation (this one often doesn't deserve a panel and might be a good one to special case)
    
#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    // Executable loading errors
    NSExecutableNotLoadableError = 3584,                    // Executable is of a type that is not loadable in the current process
    NSExecutableArchitectureMismatchError = 3585,           // Executable does not provide an architecture compatible with the current process
    NSExecutableRuntimeMismatchError = 3586,                // Executable has Objective C runtime information incompatible with the current process
    NSExecutableLoadError = 3587,                           // Executable cannot be loaded for some other reason, such as a problem with a library it depends on
    NSExecutableLinkError = 3588,                           // Executable fails due to linking issues
#endif /* MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED */
    
    // Inclusive error range definitions, for checking future error codes
    NSFileErrorMinimum = 0,
    NSFileErrorMaximum = 1023,
    
    NSValidationErrorMinimum = 1024,
    NSValidationErrorMaximum = 2047,

#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    NSExecutableErrorMinimum = 3584,
    NSExecutableErrorMaximum = 3839,
#endif /* MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_2_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED */

    NSFormattingErrorMinimum = 2048,
    NSFormattingErrorMaximum = 2559,
    
#if MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    NSPropertyListReadCorruptError = 3840,                  // Error parsing a property list
    NSPropertyListReadUnknownVersionError = 3841,           // The version number in the property list is unknown
    NSPropertyListReadStreamError = 3842,                   // Stream error reading a property list
    NSPropertyListWriteStreamError = 3851,                  // Stream error writing a property list

    NSPropertyListErrorMinimum = 3840,
    NSPropertyListErrorMaximum = 4095
#endif /* MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED */
    
};

Apr 13, 2012

How To: Install TouchXML for ios

1. download TouchXML from github
2. add the sources to your project
3. In project->build settings->header search paths:
add /usr/include/libxml2
4. In project->targets->build phases->link library with binaries:
add "libxml2.2.7.3.dylib"

Mar 30, 2012

How To: Install lxml on Ubuntu

sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python2.6-dev
easy_install --allow-hosts=lxml.de,*.python.org lxml

List of commands for MySql and Django


mysqladmin.exe -u root -p create myapp
python manage.py syncdb
mysql -u root -p
sudo /etc/init.d/apache2 restart

Mar 18, 2012

OpenSSH configuration file

Putty is a lovely ssh program, but I love console2 even more.

To use ssh to connect to Amazon EC2 server, you need cygwin to run openssh in Windows environment.
The command is (under cygwin):

ssh -i MySite.pem ubuntu@xxx.amazonaws.com
To make the command shorter, create "~/.ssh/config"
and add:

Host MySite
User ubuntu
Port 22
IdentityFile ~/.ssh/MySite.pem
HostName xxx.amazonaws.com

To connect, just type:

ssh MySite

Mar 16, 2012

Setting selective sync of Dropbox on Amazon EC2 server

Dropbox provides an easy to backup the server. However, the default setting synchronizes all of the files to the server, which is very annoying.
I don't want all of my personal stuff to be stored in a public server.

In order to select the file which you would like to sync, download dropbox.py
and type the following commands in the terminal:
python dropbox.py exclude add ~/Dropbox/*
python dropbox.py exclude remove ~/Dropbox/<folder-to-sync> 

The first command excludes all of files from your dropbox.
The second one adds the folder which is going to be synchronized.

Mar 7, 2012

Setting up Django on ubuntu



Here are the steps to setup Django on Amazon EC2 server:
The image is ubuntu-maverick-10.10-amd64-server-20101225
Choose the ebs one, otherwise you will lose everything after you shutdown your server
  1. sudo apt-get update
  2. sudo apt-get install apache2
  3. wget http://www.djangoproject.com/download/1.3/tarball/
  4. mv index.html Django-1.3.tar.gz
  5. tar xzvf Django-1.3.tar.gz
  6. cd Django-1.3
  7. sudo python setup.py install
  8. sudo  apt-get install libapache2-mod-wsgi
  9. create "/home/ubuntu/mysite/django-server.wsgi"
  10. import os, sys
    sys.path.append('/home/ubuntu/')
    sys.path.append('/home/ubuntu/mysite')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
  11. sudo /etc/init.d/apache2 start
  12. cd  /etc/apache2/sites-available
  13. sudo cp  default mysite
  14. edit "mysite"
  15. Listen 8000
    <VirtualHost *:8000>
            WSGIScriptAlias / /home/ubuntu/mysite/django-server.wsgi
            WSGIDaemonProcess server1piece user=www-data group=www-data processes=1 threads=10
            ServerAdmin webmaster@localhost
            DocumentRoot /home/ubuntu/
            Alias /static/admin/ /home/ubuntu/Django-1.3/django/contrib/admin/media/
  16. a2ensite mysite
  17. sudo /etc/init.d/apache2 reload
  18. sudo /etc/init.d/apache2 restart
  19. cd ~
  20. django-admin startproject mysite
  21. cd ~/mysite
  22. django-admin startapp myapp 
  23. python manage.py runserver 0.0.0.0:8000

Dec 10, 2011

Open source software for Windows Mobile


Just played around my phone, and saw a list of "software disclaimer", that includes:

  1. Boost
  2. FreeImage
  3. Lua
  4. Luabind
  5. OpenGL
  6. STLPort 5.0
  7. RapidXML
  8. SWIG
  9. BString
It seems that open source softwares are something that all developers should know. Especially non-GPL ones

Nov 17, 2011

My Google Chrome extensions

Here is the list of my Chrome extensions:

1. Google Mail Checker
2. Google Dictionary
3. Yet Another Google Bookmarks Extension
4. Evernote : Google Notebook is the best online notebook, but Google has stopped to its support. Evernote is an acceptable replacement, but not as easy-to-use as Google Notebook. Evernote is my temporary solution for now.

Goodbye Firefox!!!

Firefox was a good browser. However, the newer versions of Firefox have very poor compatibility with existing extensions. I am tired of finding new extensions for every new update. New technologies should help us finish our tasks efficiently, instead of giving us more tasks to do.

My #1 candidate for browser is Google Chrome. It is fast, stable and has the replacements for all of  my current Firefox extensions. Good job Google!

Jul 11, 2011

A Sleep function for VIM

I need to let VIM wait for cscope.exe to rebuild the tag file, but there are no build-in sleep function for VIM, so I made one here:

"a sleep function which allows vim to wait for the other processes to finish
com! -complete=command -nargs=+ Sleep call s:Sleep(<q-args>)
fun! s:Sleep(millisec)
  let ct = localtime()
  let dt = 0
  while dt < (a:millisec/1000)
    let dt = localtime() - ct
  endwhile
endfun

Just put it into your _vimrc.
To invoke it, type ":Sleep 10000" to let VIM wait for 10 secs.

Apr 1, 2011

igoogle gadget malfunction

After my firefox is upgraded to 3.6.16, the igoogle compound gadget suddenly disappears, and all of my gadget spreads all over my igoogle homepage. I tried to add it back, but the system says "The Compound gadget is no longer supported and the individual gadgets that it contained have been added to your iGoogle page."

Solution: delete all cookies in my firefox.

Nov 20, 2010

Ubuntu notes

Install GVIM: sudo apt-get install gnome-vim
Install boost: sudo apt-get install libboost*

Link a boost library: g++ -lboost_filesystem
Location of boost header: /usr/include
Location of boost lib: /usr/lib

Modify "autoexec.bat": sudo vim /etc/profile
Modify environment variable: export RCSSBASEDIR=/home/username/rcss

Remove resource limitation: ulimit -s unlimited

Aug 5, 2010

Draw confusion matrix in Matlab

Generate confusion matrix in Matlab:
data = rand(10, 10)
imagesc(data)
colormap(gray)
colorbar

Result:

Jun 25, 2010

My neocomplcache setting

As requested, here is my .vimrc setting for neocomplcache.
Beware that the following setting works only for "ver.5" branch.
You have to check it out from github.

"------------------------------neocomplcache---------------------------------------

" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1
" Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1

let g:neocomplcache_auto_completion_start_length = 3
let g:neocomplcache_manual_completion_start_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'

" Define keyword.
if !exists('g:neocomplcache_keyword_patterns')
    let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '\h\w*'

" snippets expand key
imap  <silent><expr><TAB>  neocomplcache#plugin#snippets_complete#expandable() ? "\<Plug>(neocomplcache_snippets_expand)" : (pumvisible() ? "\<C-e>" : "\<TAB>")
"imap  <silent><expr><TAB>  neocomplcache#plugin#snippets_complete#expandable() ? "\<Plug>(neocomplcache_snippets_expand)" : "\<C-e>"
smap  <TAB>  <RIGHT><Plug>(neocomplcache_snippets_jump)
inoremap <expr><C-e>     neocomplcache#complete_common_string()

Jun 17, 2010

SuperTab complete for neocomplcache

As I said in my previous post, neocomplcache is a very powerful vim plugin.
It incoporates the funtionality of SnipMate and  AutoComplPop while providing efficient search
for potential completion items.

However, SuperTab does not support neocomplcache. It is very bad since I like to tab complete
everything, including snippets. Here is the solution -- put the following in you .vimrc:

imap  <silent><expr><tab>  neocomplcache#sources#snippets_complete#expandable() ? "\<plug>(neocomplcache_snippets_expand)" : (pumvisible() ? "\<c-e>" : "\<tab>")
smap  <tab>  <right><plug>(neocomplcache_snippets_jump) 
inoremap <expr><c-e>     neocomplcache#complete_common_string()

The above setting allows you to trigger a snippet with "tab" key when possible. If not, it will simply trigger omni completion. I set it to complete the longest common string. It is just a personal taste. You can set it to other type of completion as well.

*Update 2010/12/11 for necomplcache V5.2 compatiblity
*Update 2012/04/24 for necomplcache V7 compatiblity

May 20, 2010

Access Windows XP files from Windows 7

I spent 4 hours today to figure out how to enable the file sharing of Windows XP.
The key difficulty is that there are too many possible reasons to make the file sharing stop working.
Microsoft should make it easier for such a common task.

Basically, all you need is to follow the instruction from
http://www.crn.com/white-box/59200376


1. To enable the network Guest account on XP Home and Pro, click Start, click Run, type: net user guest /active:yes, and hit Enter.
2. Ensure there is no password for the Guest account: click Start, click Run, type: control userpasswords2, and hit Enter. Click once on Guest, click Reset Password, and then click OK without entering a new password.
3. Be aware that Windows XP, when installed on an NTFS disk partition and using simple file sharing, blocks network access to the Program Files and Windows directories as well as users folders within the Documents and Settings directory. This behavior is by design.
4. There are two registry keys to check on XP that have the potential to cause network headaches. The first is: HKEY_LOCAL_MACHINE/System/CurrentControlSet/Control/Lsa
5. Ensure that restrictanonymous is set to 0. Ignore the restrictanonymoussam entry that looks similar and may also appear.
6. Older versions of Norton Anti-Virus set a value for IRPStacksize in the registry that is too low for XP. In fact, XP doesn't even need this registry key. If you have it in your registry, thank Symantec (NSDQ:SYMC) and then delete it. If you determine that the XP registry has this unneeded entry, check this registry location:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Lanmanserver/Parameters. You can read more about this issue from Symantec and Microsoft.


Basically, all you need is to follow the instruction from
But it is not enough. You also need to turn "simple file sharing" on.

from http://support.microsoft.com/?scid=kb;en-us;304040&x=5&y=10
To turn Simple File Sharing on or off in Windows XP Professional, follow these steps:

  1. Double-click My Computer on the desktop.
  2. On the Tools menu, click Folder Options.
  3. Click the View tab, and then select the Use Simple File Sharing (Recommended)check box to turn on Simple File Sharing. (Clear this check box to turn off this feature.)

 
TEMPLATE HACKS AND TWEAKS BY [ METAMUSE ] BLACKCAT 1.1
/scripts/shBrushJScript.js'/>