Skip to content

Instantly share code, notes, and snippets.

comet(Req) ->
Body = Req:recv_body(),
io:format("~nBody: ~p~n", [Body]),
Socket = Req:get(socket),
inet:setopts(Socket, [{active, once}]),
Response = connection:handle_json(Body),
inet:setopts(Socket, [{active, false}]),
io:format("~nSending Response: ~s~n", [Response]),
Req:ok({"application/json", [], Response}).
@Psli
Psli / application.html.erb
Created March 2, 2011 06:24 — forked from ryanb/application.html.erb
simply authenticate
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
@Psli
Psli / m3.rb
Created March 2, 2011 09:20
rails3 app template
# remove files
run "rm README"
run "rm public/index.html"
run "rm public/images/rails.png"
run "cp config/database.yml config/database.yml.example"
# install gems
run "rm Gemfile"
run "curl -L https://github.com/Psli/rails3-app-template/raw/master/Gemfile > Gemfile"
@Psli
Psli / gist:938931
Created April 23, 2011 20:13 — forked from xdite/gist:758319
Ruby / Rails Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@Psli
Psli / m31.rb
Created May 5, 2011 06:42
rails 3.1 m
# remove files
run "rm README"
run "rm public/index.html"
run "rm app/assets/images/rails.png"
run "cp config/database.yml config/database.yml.example"
# install gems
run "rm Gemfile"
run "curl -L https://gist.github.com/956650.txt > Gemfile"
@Psli
Psli / gemfile
Created May 5, 2011 06:49
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.0.beta1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Asset template engines
gem 'sass'
gem 'coffee-script'
@Psli
Psli / cmd.txt
Created May 5, 2011 15:39
cmd.txt
rails new test -d mysql -Tm https://gist.github.com/956645.txt
@Psli
Psli / redis-server
Created May 9, 2011 18:55 — forked from tessro/redis-server
A CentOS initscript for Redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
@Psli
Psli / buttons.html
Created May 15, 2011 09:13 — forked from OllyHodgson/buttons.html
A nice CSS button style for <a> elements. Tested in IE6-9, Firefox 3.6-4, Chrome 11, Safari 5, Opera 11.
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie6"><![endif]-->
<!--[if IE 7 ]><html class="ie7"><![endif]-->
<!--[if IE 8 ]><html class="ie8"><![endif]-->
<!--[if IE 9 ]><html class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html><!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<title>CSS Buttons</title>
@Psli
Psli / ruby-1.9-tips.rb
Created May 15, 2011 12:21 — forked from corntrace/ruby-1.9-tips.rb
Ruby 1.9 Tips
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"