Skip to content

Instantly share code, notes, and snippets.

@tka
tka / test.rb
Last active August 29, 2015 14:02
大概是這樣
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
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"
@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
Start: Fri Jul 24 16:07:45 2015
HOST: home Loss% Snt Last Avg Best Wrst StDev
1.|-- gateway 0.0% 10 0.3 0.2 0.2 0.3 0.0
2.|-- 175-182-237-1.adsl.dynami 0.0% 10 7.2 7.0 6.8 7.2 0.0
3.|-- h129-192-72-46.seed.net.t 0.0% 10 7.4 7.2 6.8 7.6 0.0
4.|-- R56-137.seed.net.tw 0.0% 10 7.4 7.2 6.9 7.8 0.0
5.|-- R56-158.seed.net.tw 0.0% 10 9.8 8.6 7.7 9.8 0.3
6.|-- h74-192-72-123.seed.net.t 0.0% 10 7.8 7.6 7.3 7.8 0.0
7.|-- 140.111.255.129 0.0% 10 148.4 147.6 146.0 149.0 1.1
@tka
tka / example.aes.source
Last active August 29, 2015 14:26
load env var from openssl
A=123
B=456
C=A1B2C3
FOO=bar
@browser = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox",
:url => "http://www.google.com",
:timeout_in_second => 60
@browser.start_new_browser_session
@browser.open "/"
@browser.type "q", "Ruby Tuesday #11"
@@asset_timestamps_cache = {}
@@asset_timestamps_cache_guard = Mutex.new
# Use the RAILS_ASSET_ID environment variable or the source's
# modification time as its cache-busting asset id.
def rails_asset_id(source)
if asset_id = ENV["RAILS_ASSET_ID"]
asset_id
else
<ul>
<li>AAA</li>
<div class="foo">
<li class="bar">BBBB</li>
</div>
</ul>
<li class="categories">
<div class="col">
<label class="desc">日記分類</label>
<select>
<option>----------請選擇一個分類----------</option>
<option>滿月</option>
<option>第一次不依靠攙扶會自己行走</option>
<option>幼稚園開學</option>
<option>百日禮</option>
<option>收涎</option>
<li class="categories">
<label class="desc">日記分類</label>
<div class="col">
<select>
<option>----------請選擇一個分類----------</option>
<option>滿月</option>
<option>第一次不依靠攙扶會自己行走</option>
<option>幼稚園開學</option>
<option>百日禮</option>