If you see it

Live for passion

Add Your IntelliJ12 Icon to Red Hat Panel

Installing IntelliJ 12 For Red Hat 6 Enterprise

Download the tar.gz and untar it by tar xvfz ideaIU-12.1.4.tar.gz, you can move the directory to somewhere for your convenience, you need it later for installing and starting IntelliJ.

Navigate to your IntelliJ directory and run bin/idea.sh to install IntelliJ.

Navigate to your panel and right click.

image

Create custom launcher.

image

Add command and icon to the config.

image

Markdown Time Tricks

The blog is written in Markdown syntax, and I’m using Mou as the text editer to see the blog preview at the same time. There are some time saving tricks I noted down.

Use cmd + k for inline code

Use shift + ctrl + l for link syntax

Use cmd + shift + I for adding new image syntax

Use cmd + b for adding bold to words

Use cmd + i for adding emphasize to words

Use cmd + enter for real new line

Use Sublime 2 Efficiently

As the note I had before, for IDE or text editor, there are many shortcuts and key combinations will enable us to work with them moving faster. I always prefer learn by steps due to the brain volume…

Logistics - efficient way to use Mac

cmd + H : hide your window cmd + alt + H : hide other windows

ctrl + F2 : move focus to menu bar ctrl + F3 : move focus to dock ctrl + F8 : move focus to status bar

Editing

cmd + enter : insert line after cmd + shift + enter: insert line before

cmd + d : select word cmd + l : select line

cmd + k, cmd + u/l : convert to upper/lower case

ctrl + m : jumpt to match bracket

cmd + j : combine two lines

alt + mouse : select by columns ctrl + k : delete to the end

Build

cmd + b : build based on your code language

Debugging With Heroku

Install Heroku Toolbelt, and you should be able to run heroku from your command tool

1
2
3
4
5
6
7
8
$ heroku apps
=== My Apps
xxx
xxxx
$ heroku open --app your-app-name
Opening return-inventory... done
$ heroku logs
$ heroku run rake db:migrate --app return-inventory

Run rails with production settings in order to debug locally

1
2
$ brew install memcached
$ rails s -e production
1
RAILS_ENV=production rake db:migrate

/Applications/Postgres.app/Contents/MacOS/bin/createdb inventory_production

Switch DB From Sqlite3 to Postgres in Rails App

Switch from sqlite3 to postgres

Step 1: modify Gemfile
1
$ gem 'pg'
Step 2: modify database.yml

Change the database adapter and database name in database.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
development:
  adapter: postgresql
  encoding: utf8
  database: inventory_development
  host: localhost
  pool: 5
  timeout: 5000

test:
  adapter: postgresql
  encoding: utf8
  database: inventory_test
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  encoding: utf8
  database: inventory_production
  pool: 5
  timeout: 5000

Note: You don’t need db/xx in the database part cause postgres is not like sqlite3 provided a file under db folder.

Step 3: create database

You need to create database in postgres based on the name you specified in database.yml, all development, test and production. I used PostgresApp and then:

1
/Applications/Postgres.app/Contents/MacOS/bin/createdb YOUR_DB_NAME

You can follow the documentation and add the bin to your path.

Step 4: Rails DB migrate

Run the following in terminal:

1
2
3
$ bundle update   
$ bundle install  
$ rake db:migrate

IMPORTANT NOTE If you are running your rails server in different mode locally, like production mode, you need to use the following line to performe your db migration.

1
RAILS_ENV=production rake db:migrate
Note

1. If you are planning deploy to heroku, heroku will create the database for you according your database.yml

2. If you are planning deploy to heroku via Snap, you need to go change the configuration for the build to use postgresql manually. Snap will pick up your db choice when you added it to it, but now monitoring it all the time for now.

Bootstrp Ruby on Rails

Install Rails 3

Prerequisite: Ruby

1
2
$ ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.4.0]
1
2
$ gem install rdoc ## to avoid "file 'lib' not found" error  
$ gem install rails --version "=3.2.14"

As Aug 6th, 2013, the following installed rails 4.0.0, I chose to use Rails 3 for now. Here is how downgrade.

1
2
3
4
$ gem install rails 
$ gem uninstall rails
Successfully uninstalled rails-4.0.0
$ gem install rails --version "=3.2.14"

Sqlite3 With Android

Prerequisite: set up adb command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ adb devices ## I have one real device and one emulator  
List of devices attached  
xxxxxxxxxxxx  device  
emulator-5554 device   

$ adb -s emulator-5554 shell ## To access specific device's shell and then use sqlite3 command
root@android:/ # sqlite3
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

$ adb -s emulator-5554  pull /system/xbin/sqlite3
4005 KB/s (67880 bytes in 0.016s)
s
$ adb -s 015d28569058200a push sqlite3 /system/xbin/
failed to copy 'sqlite3' to '/system/xbin//sqlite3': Read-only file system

Install Java 7 on Mac

Install JDK 7 for Mac OS X 10.8.4

To install Java 7 (Java Development Kit 7, JDK 7), you need download jdk7 from Oracle site ( here ), you will have jdk-7u25-macosx-x64.dmg and just double click to install it.

JDK 7 JDK 7 update 25

1
2
3
4
5
6
7
8
9
10
11
12
$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.7.0_25, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
    1.6.0_51-b11-457, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_51-b11-457, i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home

Note

Java Runtime Environment, JRE is differrent from JDK, after install this, you won’t be see the change in your terminal by java -version.

JRE

Quote from here.

The “JDK” is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The “JRE” is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs.

Typically, each JDK contains one (or more) JRE’s along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

Google Map on Android With Play Service 7

Our side project: TrakéMoi

The previous blog post solved some basic problems you may have: Android App With Google Map API V2

Google Play Service 7 installation/upgrade

Option 1

You can either run $ android sdk, select to install your Google Play Service, also api 16, for some reasons, you may need this to support the play 7.
alt text

Option 2
1
2
3
$ android update sdk --no-ui --force --filter platform-tools,extra-android-support,android-17,sysimg-17,extra-google-google_play_services  

$ android update sdk --no-ui --force --filter android-16

GMS-MVN help setup

Add the gms-mvn as your git submodule.

.gitmodules
1
2
3
[submodule "vendor/gms-mvn"]
  path = vendor/gms-mvn
  url = git://github.com/JakeWharton/gms-mvn-install.git

And automate the installation.

setup.sh
1
2
3
4
5
6
7
8
9
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/build-tools

git submodule init
git submodule update

git submodule foreach git pull origin master

cp vendor/gms-mvn/gms-mvn-install.sh ${ANDROID_HOME}/extras/google/google_play_services/libproject/google-play-services_lib/
(cd ${ANDROID_HOME}/extras/google/google_play_services/libproject/google-play-services_lib/ && ./gms-mvn-install.sh 7)

Update pom.xml

Add Google Play Service 7 to pom, also update the android-maven-plugin to 3.6.0.

pom.xml partially
1
2
3
4
5
6
7
8
9
10
11
12
13

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>7</version>
    <type>apklib</type>
</dependency>

<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.6.0</version>