Skip to content

Instantly share code, notes, and snippets.

View liuzxc's full-sized avatar
🎯
Focusing

刘兴起 liuzxc

🎯
Focusing
View GitHub Profile
@liuzxc
liuzxc / install
Last active March 2, 2016 10:04
Install pip and virtualenv for Ubuntu
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
sudo apt-get install redis-server
pip install flower
@liuzxc
liuzxc / 0_reuse_code.js
Created January 14, 2016 02:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

become active record migration expert (Rails 4.0.2)

workflow:

create model

$ rails g model NameOfModel
    invoke  active_record
    create    db/migrate/YYYYMMDDHHMMSS_create_name_of_models.rb

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@liuzxc
liuzxc / check_purchase_status.rb
Last active August 29, 2015 14:14
Checks the android purchase and consumption status
# -*- encoding : utf-8 -*-
require 'net/http'
require 'json'
module CheckPurchaseStatus
CLIENT_ID = "xxxxxxxxxxxx"
CLIENT_SECRET = "xxxxxxxxxx"
REDIRECT_URIS = "https://xxxxxxxxxx"
Something else I found helpful along the way (as I had old stuff installed):
gem uninstall --install-dir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 rails