Wonderful Editor Sublime Text 2

Better than TextMate

  • Cross platform, Mac/Linux/Windows all works!
  • Well designed UI and highly customizable!
  • Support Chinese characters!
  • Rich and convenient package system, easy to hack
  • Support VIM commands
  • Great support to GIT
  • Other great packages, eg. SFTP …

Useful packages

You need to install package control before using these packages.

Convenient shortcuts

Below are some interesting keys in Mac:

  • Cmd Shift p : open command window
  • Cmd t : file finder, support fuzzy query!
  • Cmd Shift [ or ] : jump to left or right file
  • Cmd w : close file
  • Cmd r (Cmd t + @) : find id in html file
  • Cmd t + # : find class or html tags in html file
  • Cmd l : select line/s
  • Cmd (number) : jump to file (number)
  • Cmd t + :(number): jump to line (number)
  • Cmd k b : toggle sidebar
  • Cmd Opt 2 : split to 2 screens
  • Ctrl Shift (number) : move file to screen (number)

Setup package control

It is very simple to setup package control. To check if you successful install, go to Preference -> Browse Packages , go up a folder, and check in Installed Packages .

After installed, you should find Package Control … in command window. Eg. Package Control - Install will connect to remote repo. and show all packages

Setup VIM commands

Vintage provides simulated vim commands in Sublime Text. Default settings ignored it, so you just have to modify this, and add a shortcut key to use it. Official is shared in vintage document and a simple tutorial

Remove Vintage from ignore_packages

  1. Preferences -> Settings - Default
  2. Edit file, remove Vintage from ignored_packages
1
2
3
4
  // List any packages to ignore here. When removing entries from this list,
  // a restart may be required if the package contains plugins.
  //"ignored_packages": ["Vintage"]
  "ignored_packages": []
  1. Preferences -> Settings - User, and do step 2

Setup shortcut key binding

  1. Preferences -> Key Bindings - User ( I use User mode, since in Default mode, updating the software, will reset default settings)
  2. Edit file, add your preferred shortcut key
1
2
3
4
5
6
7
8
9
10
[
  // Add key shortcut to VIM, using escape key in this example
  { "keys": ["escape"], "command": "exit_insert_mode",
      "context":
      [
          { "key": "setting.command_mode", "operand": false },
          { "key": "setting.is_widget", "operand": false }
      ]
  }
]

Now everytime you press ‘escape’ key, it will switch to VIM edit mode!

If you want VIM commands, you can install Vintage Ex through package control.

Setup SFTP

The official website will teach you to install, and configure parameters. I use this simple tutorial to setup remote server and sync remote to local .

Note that, when creating a local repo., sftp-config.json will be created, and server settings are done in this file. I made a few tweaks to make it work better.

1
2
3
4
5
6
7
"save_before_upload": true,
"upload_on_save": true # when save, file will be uploaded, ensure remote file be up to date
"sync_down_on_open": false,
"sync_skip_deletes": false,
"confirm_downloads": false,
"confirm_sync": false,
"confirm_overwrite_newer": true, # warning if remote is being modified

Very simple and works well. Only a pity that .git is not synced, so git tools cannot be used.

Setup Rails Related Files

Just install the package via package control, and add key binding, reference Default (OSX).sublime-keymap in github source.

Default uses Cmd Shift o .

Setup Rails Migration List

Just install via package control. Default uses Cmd Shift m .

Setup Red Mine on Heroku

My customization

I followed this tutorial, with only a minor customization.

  1. Use mysql2 instead of mysql in database.yml
  2. Use master branch in Red Mine
  3. Remove sqlite3 related gems in Gemfile
  4. Add themes in public/themes, and switch theme in Administrator/settings/display

Deploying with Heroku

I added a few steps from above tutorial, since this is my first deploy to Heroku.

  1. Installing the Heroku toolbelt
  2. Use heroku login to switch to heroku env.
  3. Use heroku keys:add ~/.ssh/id_rsa_x.pub to setup key for ssh session when doing git push
  4. Restart heroku by heroku ps:restart and use heroku open to try out your app
  5. Edit config/environment.rb to comment out the exit in case of plugins in vendor: # exit 1

Note:

  • This other reference shows clearly the fix of vendor plugin issue. Thanks.

  • This other reference is very informative, but slightly out of date.

I Love Mongolia

Mongolia is beautiful. It has a lot of amazing scenery, and you can experience tough and rural life.

rural places with shepherds

Mongolia has a rich amount of natural resource, and the largest industry are mining and sightseeing. Since Mongolia is not advance in technology, many countries came to “help”, and one of the most largest country is China. They brought hugh money in, but also much society problem. It’s ironic.

Looking back, the people I met are mostly friendly (as long as they know I am not from China…) and I really enjoyed being with them.

200km desert

This is a very famous desert as it cross 200km. Although only around 200m high, it was very difficult to climb up, almost fell dead reaching the top. The happy man in the photo is our driver. :P

glacier in summer

It is June, 30~40 degress celcius, and the glacier is still so thick. It is legendary …

ancient drawing

This place looks like it has been hit by comet. The rocks are strange, and many ancient drawings are preserved.

Hope you enjoyed these photos as much as I did!

Automate Purchases With Paypal

To run purchases automatically without needing customer’s continuous authorization, You need to get baid (billing agreement id). Afterwards you can use Paypal reference transaction API to do future purchases.

Below is an example using active merchant gem to run Paypal API

active merchant example to get paypal baid by paypal express checkout api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Initialize Paypal API
def initialize
  @paypal ||= activemerchant::billing::paypalexpressgateway.new(
      :login => <paypal email account>,
      :password => <paypal password>,
      :signature => <paypal signature>,
end

# Ask for user agreement
def create
  setup_response = @paypal.setup_purchase(
  0,
  :return_url        => <your server path>,
  :cancel_return_url => <your server path>,
  :description => <product description>,
  :currency => "USD",
  :custom => "a customized data",
  :billing_agreement => {
      :type => 'MerchantInitiatedBilling', # Use this to retrieve BAID => Billing Agreement ID
      :payment_type => "Any" # seemed optional
  })
  redirect_to @paypal.redirect_url_for(setup_response.token)
end

# Get BAID
def callback
  response = @paypal.create_agreement(params[:token])
  if response.success?
      baid = response.params["BillingAgreementID"]
  end
end

Tips to Setup & Use Octopress

Octopress, really is … for hackers!

Basically, in octopress, blogging is like programming

To create post, do rake new_post[title]

To generate result, do rake generate

To preview, do rake preview

To deploy, do rake deploy

And … I blog with VIM!!

Setup Octopress

I tried to deploy Octopress by github, since I already have an account.

However, the path wasn’t too smooth today …

I setup a repository, Josephu (git@github.com:Josephu/Josephu.git to be exact), and run the command:

rake setup_github_pages

rake generate; rake deploy

But connecting to http://josephu.github.com failed!

It took me some time to figure out that I named the repo wrongly …

It is suppose to be josephu.github.com (git@github.com:Josephu/josephu.github.com.git)

Nice …

Customize Octopress

To make the theme feel right, I made a few fixes in CSS & html.

Basically, octopress provided scss files to customize in sass/custom and html content in source

  • Background Color

The color can be adjusted in sass/custom/color. They are defined as sass variables.

Since I want to add some texture to the banner, I got some free texture from amazingtextures and add css in sass/custom/style, attach to the banner in source/layout. It looked much better this way.

Note that the image should be placed in source/images, and in scss, use image-url to get the correct path.

  • Font Size

The blockquote font is simply too large, so overriding with css is more comfortable for the eye.

  • Optimize Speed

Texture is compressed and croped to reduce transfer size

So This Is Just The Beginning

Have fun blogging!