This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# originated from http://stackoverflow.com/questions/2393697/look-up-all-descendants-of-a-class-in-ruby | |
# | |
class Class | |
def descendants | |
result = {} | |
ObjectSpace.each_object(::Class) {|klass| result[klass] = klass.descendants if klass < self } | |
result | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before xxx :only => xxx みたいなやつ | |
# http://blog.alastairdawson.com/2010/07/27/a-sinatra-before-only-filter/ | |
# 若干書き換えて[]を不要にした | |
module Sinatra | |
module BeforeOnlyFilter | |
def before_only(*routes, &block) | |
before do | |
routes.map!{|x| x = x.gsub(/\*/, '[^/]')} | |
routes_regex = routes.map{|x| x = x.gsub(/\//, '\/')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PATH_TO_MODELS = "path/to/models/" | |
class Module | |
def descendants | |
result = {} | |
ObjectSpace.each_object(::Class) {|klass| result[klass] = klass.descendants if klass < self } | |
result | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
class <<self | |
def quote_column_name(column_name) | |
"#{quoted_table_name}.#{connection.quote_column_name(column_name)}" | |
end | |
end | |
def incr(attribute, by) | |
quoted_attribute = self.class.quote_column_name(attribute.to_s) | |
self.class.where(id: id).update_all("#{quoted_attribute} = #{quoted_attribute} + #{by.to_i}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
UNIFIED_EMOJI = %w( | |
U+2600 | |
U+2601 | |
U+2614 | |
U+26C4 | |
U+26A1 | |
U+1F300 | |
U+1F301 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# montage seems not to keep transparency. | |
# So I resized images with sips, and concated with convert. | |
Dir.glob("assets/iphone/*.png").each do |path| | |
out1 = File.dirname(path) | |
out2 = File.basename(path) | |
out = "#{out1}/xxx_#{out2}" | |
%x(sips --resampleHeightWidth 20 20 --out #{out} #{path}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT系SQLでできることとかActiveRecordでできること | |
# people | |
* name : 名前(文字列) | |
* age : 年齢(整数) | |
| id | name | age | | |
| 1 | John | 18 | | |
| 2 | Ben | 27 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<input id="foo" type="button" value="foo" /> | |
<iframe src="http://192.168.11.19:8001/to.html" id="proxy"></iframe> | |
<script> | |
window.callbacks = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# output to mysql.general_log | |
# if you want mysql to log to file, set it as `FILE`, or `FILE,TABLE` | |
log-output=TABLE | |
general_log=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "digest/sha1" | |
require "fileutils" | |
BASE_URL = "http://www.bijint.com/%{location}/tokei_images/%{time}.jpg" | |
BASE_DIR = File.expand_path("~/tmp/bijin/%{location}") | |
TEMP_PATH = File.join(BASE_DIR, "%{time}.jpg") | |
SAVE_PATH = File.join(BASE_DIR, "%{time}_%{digest}.jpg") |