Skip to content

Instantly share code, notes, and snippets.

View dfang's full-sized avatar
🎯
Focusing

fang duan dfang

🎯
Focusing
View GitHub Profile
@dfang
dfang / js_cdn_list.txt
Created December 2, 2013 11:14
javascript cdn list
http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs
http://cdnjs.com
http://www.jsdelivr.com
http://jscdn.upai.com
http://cachedcommons.org/
http://www.bootstrapcdn.com
http://www.maxcdn.com/
http://www.asp.net/ajaxlibrary/cdn.ashx‎
https://developers.google.com/speed/libraries/devguide#angularjs
@dfang
dfang / my-sublime-preferences.sublime-settings
Created December 2, 2013 17:46
my sublime preferences
{
"always_show_minimap_viewport": true,
"binary_file_patterns":
[
"*.jpg",
"*.jpeg",
"*.png",
"*.gif",
"*.ttf",
"*.woff",
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default and default-ssl to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/

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

@dfang
dfang / gist:d3ecefe66da294340026
Created May 22, 2014 08:27 — forked from dhh/gist:2492118
split a large routes.rb to multiple files
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@dfang
dfang / Termfile example
Last active August 29, 2015 14:08
Termfile example
directory = '~/Development/Work/gart360-web'
url = 'http://gart.dev:3000'
before { run "cd #{directory}" }
run 'fs'
tab do
run "tlog"
end
@dfang
dfang / gist:a58bc901c7b584cdbafc
Last active August 29, 2015 14:10
use backup and whenever with capistrano to backup database on vps
1. install bakcup and whenever gem
```
gem 'backup'
gem 'whenever'
```
2. capistrano task(for uploading config file, put it to lib/capistrano/tasks/backup.rake)
```
namespace :backup do
@dfang
dfang / gist:68f5b7667965f54dbe5c
Last active August 29, 2015 14:17
passing arguments to rake/cap task