Skip to content

Instantly share code, notes, and snippets.

@ichi
ichi / open_url.rb
Created October 5, 2011 09:42
earthquake plugin: open any url in 1tweet
# -*- coding: utf-8 -*-
Earthquake.init do
command %r{^:open\s+(\d+)\s+(\d+)$}, :as => :open do |m|
num = m[2].to_i
urls = URI.extract(twitter.status(m[1])['text'])
if !urls.empty?
if num <= urls.size
browse urls[num - 1]
@ichi
ichi / active_record.rb
Created June 7, 2012 10:51
unscopedなassociationなやつ
# config/initializers/active_record.rb
class ActiveRecord::Base
class << self
# 参考: http://techracho.bpsinc.jp/baba/2011_11_28/4729
def define_unscoped_model(name, model, options = {})
model_name = if options[:class_name]
options[:class_name].to_s
else
@ichi
ichi / gist:3910514
Created October 18, 2012 08:45
yan某
curl -s -o /dev/null -I -w '%{url_effective}: %{http_code}\n' https://twitter.com/yan\[1-100\]
@ichi
ichi / deploy.rb
Created November 13, 2012 05:28
capistrano + cakephp
#encoding: utf-8
## config/deploy.rb
# pp
require 'pp'
# capistrano-ext
require "capistrano/ext/multistage"
#!/usr/bin/env ruby
forwardings = { # sample
hoge: 'hoge.com -L 58010/10.120.1.10/3306',
fuga: 'fuga.org -L 58011/localhost/3306',
unko: 'unko.com -L 58012/222.222.222.222/3306'
}
forwardings.each do |k, v|
@ichi
ichi / convert_from_utf8mac
Last active December 17, 2015 14:39
mac濁点問題対策。itunesで吐き出したm3u8なんかにやってやる。(そのままだとandroidなんかで問題箇所がとばされちゃうから)
#!/usr/bin/env ruby
Dir[*ARGV].each do |f|
tmp = "#{File.dirname f}/_#{File.basename f}"
`iconv -c -f UTF-8-MAC -t UTF-8 #{f} > #{tmp}`
File.rename tmp, f
end
@ichi
ichi / Rakefile
Last active December 18, 2015 08:29
Rakefile。 coffeeとsassのwatchするタスクと、 schemaSpyするタスク。 cakephpなんかのときに。
# -*- coding: utf-8 -*-
require 'yaml'
require 'json'
# 設定読み込み
@dir = File.dirname(__FILE__)
@env = ENV['APPLICATION_ENV'] || 'develop'
@config = YAML.load_file(ENV['RAKE_CONFIG_YAML'] || 'config/rake_config.yml')[@env] || {}
@db_config = JSON.load `php -r "require_once('app/Config/database.php'); echo json_encode((new DATABASE_CONFIG())->#{@env});"`
autoload -U add-zsh-hook
# Growl notify long running command
__timetrack_threshold=20 # seconds
function __my_preexec_start_timetrack() {
local command=$1
export __timetrack_start=`date +%s`
@ichi
ichi / tabs.coffee
Last active December 26, 2015 07:09
タブ
$ ->
do init = (context = document)->
$('.tabs[data-target]', context).each ->
$nav = $(@)
$tabs = $nav.find 'li'
$contents = $("##{$nav.data 'target'} > .tab_contents")
# default class
$nav.data 'class', $nav[0].className
@ichi
ichi / toggle_link.coffee
Last active December 26, 2015 07:09
リンクで表示トグル