Skip to content

Instantly share code, notes, and snippets.

View yuroyoro's full-sized avatar
🍣
🍣

しいたけ yuroyoro

🍣
🍣
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>fxxk_it_alert</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Users/ozaki/bin/fxxk_it_alert.scpt</string>
@yuroyoro
yuroyoro / gist:5003402
Created February 21, 2013 09:12
curlコマンドで、HTTP のステータスコードをすばやくしらべる!
curl -s http://www.ietf.org/rfc/rfc2616.txt | grep -E '^\s+\|?\s+"[0-9]{3}"\s+;' | sed -r 's/^\s+\|?\s+"([0-9]+)"\s+;.+:(.*)$/\1 : \2/g'
@yuroyoro
yuroyoro / httpstatus.hs
Created February 21, 2013 05:36
一般的な Web Programmer ならば、HTTP Status code はすべて暗記していると聞きました。 しかし、僕は初心者なので、なかなか覚えきれていないので、HTTPのステータスコードをさがすのに便利なツールを用意しました。 httpstatus.hs です。インストール方法は 適当にコンパイルしてください。
{- GHC 7.4 -}
import System.Environment
import Data.List
main = do args <- getArgs
mapM_ (putStrLn . show) (filterStatus args)
data HttpStatus = HttpStatus {
status::String, message::String}
@yuroyoro
yuroyoro / summarize_sql_log.rb
Last active December 13, 2015 16:49
RailsのSQLログを適当に集計するスクリプト
#!/usr/bin/env ruby
# Usage :
# summarize_sql_log.rb <log_file_name>
#
# Output example:
#
# User Load Count:1408 775.2000 ms
# Blog Load Count:654 434.3000 ms
# Comment Load Count:454 341.0000 ms
@yuroyoro
yuroyoro / ltsv_parser.hs
Created February 6, 2013 11:41
Haskellの練習でLTSVパースするヤツ
import qualified Data.Map as M
import Data.List.Split
type Field = (String,String)
type Fields = M.Map String String
main = do cs <- getContents
mapM_ showTree' $ parse cs
showTree' :: Fields -> IO()
@yuroyoro
yuroyoro / sliding.rb
Created December 27, 2012 10:20
RubyでScalaのIterator#slidingを実装してみた
class Array
def sliding(n)
self.inject([]){|xs,e| xs.last.tap{|r| r.nil? ? xs << [e] : if r.length < n then r << e else xs << r.dup.tap{|_| _.shift ; _ << e } end }; xs}
end
end
[42] pry(main)> arr = (1..10).to_a
[43] pry(main)> arr.sliding(3)
[
@yuroyoro
yuroyoro / attr_inquireable.rb
Last active May 10, 2017 20:35
AttrInquirable wraps value of attribute in ActiveSupport::StringInquirer.
# AttrInquirable
# wraps value of attribute in ActiveSupport::StringInquirer.
#
# Usage:
#
# class Person < ActiveRecord::Base
# attr_inquireable :status
# end
#
# person = Person.new(:status => :pending)
100000.times do raise 'unmatch' unless {'a' => 1, 'b' => 2, 'c' => 3}.to_json == {'a' => 1, 'b' => 2, 'c' => 3}.to_json end
@yuroyoro
yuroyoro / json_bench.rb
Created December 6, 2012 07:03
MultiJsonのBackendをyajlに変えたら素のjson.gemの2倍のパフォーマンスになった件
#!/usr/bin/env ruby
# rails r tools/json_bench.rb
require 'rbench'
ar_objects1 = # 適当なActiveRecordオブジェクト一個
json_str1 = ar_objects1.to_json
ar_objects2 = # 3個ほど子テーブルをincludeさせたActiveRecordオブジェクトを70個くらいの配列に
json_str2 = ar_objects2.to_json
@yuroyoro
yuroyoro / explain_analyze_on_pg_adapter.rb
Created December 5, 2012 11:27
RailsでPostgreSQLを使うときに、"EXPLAIN"の代わりに"EXPLAIN ANALYZE"を使うようにする猿パッチ
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
def explain(arel, binds = [])
sql = "EXPLAIN ANALYZE #{to_sql(arel, binds)}"
ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
end
end
end
end