Skip to content

Instantly share code, notes, and snippets.

@cofemei
cofemei / app.rb
Created March 15, 2010 12:52 — forked from bigcurl/app.rb
Sinatra on Google AppEngine For Windows
require 'rubygems'
require 'sinatra'
get '/' do
"Hello from Sinatra running on Java!"
end
@cofemei
cofemei / cap
Created December 8, 2010 08:03
set :default_stage, "staging"
default_run_options[:pty] = true
set :rails_env, default_stage
set :application, app_name_#{rails_env}
set :deploy_to, "/u/apps/#{application}_#{rails_env}"
set :domain, server_name
set :repository, repo_url
set :use_sudo, false
set :scm, :git
set :branch, "master"
@cofemei
cofemei / gist:758359
Created December 29, 2010 09:17 — forked from xdite/gist:758319

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
function git_since_last_commit {
now=`date +%s`;
last_commit=$(git log --pretty=format:%at -1 2> /dev/null) || return;
seconds_since_last_commit=$((now-last_commit));
minutes_since_last_commit=$((seconds_since_last_commit/60));
# rvm bootstrap
apt-get -q -y update
apt-get -q -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libmysqlclient-dev libmysqlclient16
apt-get -q -y install git-core curl
apt-get -q -y install clang
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
rvm install ree
@cofemei
cofemei / node-and-npm-in-30-seconds.sh
Created December 3, 2011 03:41 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@cofemei
cofemei / warbler.conf
Created May 6, 2012 11:28
Warbler includes sqlite, ruby 1.9, skip compiled
# Disable Rake-environment-task framework detection by uncommenting/setting to false
# Warbler.framework_detection = false
# Warbler web application assembly configuration file
Warbler::Config.new do |config|
# Features: additional options controlling how the jar is built.
# Currently the following features are supported:
# - gemjar: package the gem repository in a jar file in WEB-INF/lib
# - executable: embed a web server and make the war executable
# - compiled: compile .rb files to .class files
@cofemei
cofemei / will_paginate.rb
Created July 3, 2012 09:07 — forked from henrik/will_paginate.rb
Extends will_paginate to play well with Twitter's Bootstrap (http://twitter.github.com/bootstrap/). Suggested location: config/initializers/will_paginate.rb
# https://gist.github.com/1214011
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@cofemei
cofemei / gist:3791754
Created September 27, 2012 02:04
Oracle 分頁 test
// 分頁 test
$subsids = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21');
$page = 10;
if (count($subsids) > $page) {
$totle = ceil(count($subsids) / $page);
$subsidIn = "";
for ($i=0; $i < $totle; $i++) {
$tmp = array();
@cofemei
cofemei / jedi-daemon
Created November 30, 2012 06:43 — forked from audreyt/jedi-daemon
「狂賀《簡報原力》登上銷售冠軍」活動機器人
#!/usr/bin/env perl
use 5.10.0;
use utf8;
use LWP::Simple;
use Encode 'encode';
use Encode::MIME::Header;
use File::Slurp 'slurp';
use Email::MIME;
use Email::Sender::Simple qw(sendmail);