Skip to content

Instantly share code, notes, and snippets.

View kimihito's full-sized avatar
🏠
Working from home

kimihito kimihito

🏠
Working from home
View GitHub Profile
@niklas
niklas / rails-fields-with-errors-get-class-by-nokogiri.rb
Created January 9, 2011 21:03
Add .error CSS class to all invalid form fields. Rails wraps them in div.fieldWithErrors, which still sucks in 3.0
# put this in config/initializer/fields_with_errors.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag =~ /<(input|label|textarea|select)/
error_class = 'error'
doc = Nokogiri::XML(html_tag)
doc.children.each do |field|
unless field['type'] == 'hidden'
unless field['class'] =~ /\berror\b/
@nazgob
nazgob / ctags.setup
Created January 6, 2012 13:44
ctags setup on mac
# you have ctags but it does not work...
$ ctags -R --exclude=.git --exclude=log *
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
#you need to get new ctags, i recommend homebrew but anything will work
$ brew install ctags
#alias ctags if you used homebrew
$ alias ctags="`brew --prefix`/bin/ctags"
@nefo-mi
nefo-mi / mention.rb
Created May 8, 2012 17:24
twitterのリプライをArduinoで通知してみた
#!/usr/bin/env ruby
# encoding : utf-8
require 'userstream'
require 'yaml'
require 'serialport'
sp = SerialPort.new("/dev/ttyACM0", 9600, 8, 1, SerialPort::NONE)
stream_config = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/config.yml'))
@rummelonp
rummelonp / faraday.md
Last active May 20, 2022 12:23
Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

API ラッパの開発には [RestClient gem][rest_client_gem] だとか
OAuth の必要なものは [Net/HTTP][net_http] + [OAuth gem][oauth_gem] を使ってた

[Twitter gem][twitter_gem] や [Instagram gem][instagram_gem] など API ライブラリのソースを読んでみると
[Faraday gem][faraday_gem] というものがよく使われてた

"------------------------------------
" sass
"------------------------------------
""{{{
let g:sass_compile_auto = 1
let g:sass_compile_cdloop = 5
let g:sass_compile_cssdir = ['css', 'stylesheet']
let g:sass_compile_file = ['scss', 'sass']
let g:sass_started_dirs = []
@hanachin
hanachin / README.md
Created September 14, 2012 01:46 — forked from tompng/gist:3719273
youtube gen playlist
@hanachin
hanachin / pomodoro.rb
Created October 10, 2012 16:45
ポモドーロたん
require 'enumerable/lazy'
work = Enumerator.new {|y| loop { y << 25 } }
rest = Enumerator.new {|y| loop { 3.times { y << 5 }; y << 15 } }
pomodoro = work.lazy.zip(rest)
pomodoro.each {|set|
work_time, rest_time = set
case set
when [25, 5]
puts "normal"
input = "Guvf grkg vf rapbqrq ba ebg13"
rot13 = (input) ->
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = "abcdefghijklmnopqrstuvwxyz"
input.split('').map (c) ->
[upper, lower].forEach (cs) ->
c = cs[(i + 13) % cs.length] if ~i = cs.indexOf(c)
c
.join("")
@hanachin
hanachin / gifs.rb
Created October 24, 2012 14:58
download gif animations from kksg.net
require 'fileutils'
require 'open-uri'
require 'json'
DIRNAME = File.join(File.dirname(File.expand_path(__FILE__)), 'gifs')
Dir.mkdir(DIRNAME) unless File.exists?(DIRNAME)
gifs = JSON.parse(open('http://kksg.net/api/gifs.json').read)
gifs.map{|gif| gif["md5"]}.each {|md5|
url = "http://kksg.net/data/gif/#{md5}"
@hanachin
hanachin / README.md
Created November 4, 2012 17:48
Sublime Text 2 Plugin AutomaticClosePurchaseDialog (works only osx)

How to use

git clone git://gist.github.com/4012751.git ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/AutomaticClosePurchaseDialog