Skip to content

Instantly share code, notes, and snippets.

View wildjcrt's full-sized avatar
🦀
have a nice day!

Jerry Lee wildjcrt

🦀
have a nice day!
View GitHub Profile
@ROFISH
ROFISH / Gemfile
Last active August 29, 2015 14:00
#ruby '2.1.0'
source 'https://rubygems.org'
gem 'rack', '~>1.5.2'
gem 'actionpack', '~> 4.1.0.beta1'
gem 'railties', '~> 4.1.0.beta1'
@wildjcrt
wildjcrt / test.rb
Created June 25, 2014 01:16 — forked from tka/test.rb
sql = "select *, (select count(books.id) from books where books.authorsid=authors.id) as books_count from authors "
authors = Author.find_by_sql(sql)
authors.first.books_count
@yhsiang
yhsiang / UPGRADE.md
Last active August 29, 2015 14:12
Note: upgrade discourse from xdite fork to docker version

UPGRADE

  1. Flush your new Discourse's database. This step is destructive; you must be absolutely certain that you are in the correct container, connecting to the correct database and that it contains no important data.

ssh root@hostname -p 2222

sudo -u postgres psql discourse <<END
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
ALTER SCHEMA public OWNER TO discourse;
class MigrateCookie < Struct.new(:app)
def call env
cookies = Rack::Utils.parse_query(env['HTTP_COOKIE'], ';,')
case cookies['_session_id']
when Array
status, headers, body = app.call(env)
headers['Set-Cookie'] =
"#{headers['Set-Cookie']}\n#{expire_old_session}"
[status, headers, body]
else
@tka
tka / benchmark.rb
Last active August 29, 2015 14:24
golang 1.5 shared library + ruby ffi
# 搭配 http://qiita.com/yanolab/items/1e0dd7fd27f19f697285 服用
require 'ffi'
require 'benchmark'
module LibGo
extend FFI::Library
ffi_lib './libgo.so'
attach_function :fib, [:int], :int
require 'sequel'
module FasterSequelTimeParser # from activerecord
module_function
def parse string
string =~ /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
microsec = ($7.to_r * 1_000_000).to_i
::Time.utc($1.to_i, $2.to_i, $3.to_i, $4.to_i,
$5.to_i, $6.to_i, microsec)
end
@wildjcrt
wildjcrt / gist:760859
Created December 31, 2010 08:27 — forked from xdite/gist:758319

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
# before
## model
class User
after_create : call_3rd_api
def call_3rd_api
xxx
end
end
@wildjcrt
wildjcrt / gist:1601405
Created January 12, 2012 16:21 — forked from xdite/gist:1599619
Debian DRBD + MySQL + HeartBeat
@wildjcrt
wildjcrt / gist:2007247
Created March 9, 2012 16:02
batch delete Kindle Personal Document js code
javascript:(function(){ var v = new RegExp("PersonalDocuments"); if (!v.test(document.URL)) { return false; } {a=document.getElementsByClassName('rowBodyCollapsed');for(var i = 0; i<a.length; i++){Fion.deleteItem('deleteItem_'+a[i].getAttribute('asin'));};return; }})();