Skip to content

Instantly share code, notes, and snippets.

@koko-u
koko-u / .watchr
Created April 29, 2011 02:18
ファイルの更新に伴いspecを実行するwatchr
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
system "bundle exec rspec #{file}"
puts
end
@koko-u
koko-u / switch_pogoplug
Created May 2, 2011 04:36
pogoplugでファイルをmount / umount
#!/bin/sh
mountpoint=/mnt/pogoplug
# find the current state of pogoplug
state=`pgrep pogoplugfs`
# if off, turn on, else off.
if [ "$state" = "" ]; then
pogoplugfs --user <email-address> --password <pogoplug_password> --mountpoint $mountpoint > /dev/null 2>&1 &
@koko-u
koko-u / mkstardicttab.rb
Created May 10, 2011 02:22
英辞郎のTXTファイルをStardictの扱えるTAB形式に変換
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 英辞郎が提供する txt ファイルを Stardict が読める .tab 形式に変換する
# iconv の Shift_jis -> Utf-8 変換はうまくないみたいなので、nkf を使いましょう。
# cat EIJI-129.TXT | nkf -w8Lu | ./mkstardicttab > eijirou.tab
# 最終的には stardict-tools の tabfile を使って
# /usr/lib/stardict-tools/tabfile eijirou.tab
# としてできたファイルを /usr/share/stardict/dic に置く
@koko-u
koko-u / .watchr
Created May 13, 2011 17:45
ファイルの更新に伴い、実行した spec の結果を gnome に通知する watchr
def notify(title, message, image)
system "notify-send '#{title}' '#{message}' -i '#{image}' -t 2000"
end
def run_withnotify(*files)
image_root = File.expand_path("~/.autotest_images")
puts "Running: #{files.join(' ')}"
puts results = `bundle exec rspec -f p -c #{files.join(' ')}`
output, _, fail_count, _, pending_count =
*/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spendings?)?/.match(results)
@koko-u
koko-u / .irbrc
Created May 14, 2011 23:22
rails console で自動的に Hirb.enable する
require 'irb/completion'
require 'pp'
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:PROMPT][:CUSTUME] = {
:PROMPT_I => "%03n:>> ",
:PROMPT_N => "%03n:%i>",
:PROMPT_S => "%03n:>%l ",
:PROMPT_C => "%03n:>> ",
:RETURN => "=> %s\n"
@koko-u
koko-u / _error_messages.html.erb
Created May 26, 2011 21:41
rails エラーメッセージのタイトル日本語化
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= t(:header, :model => t(:user, :scope => [:activerecord, :models]),
:count => @user.errors.count, :scope => [:activerecord, :errors, :template]) %></h2>
<p><%= t(:body, :scope => [:activerecord, :errors, :template]) %></p>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@koko-u
koko-u / .gitconfig
Created June 11, 2011 09:02
.gitconfig
[user]
name = Kozaki, Tsuneaki
email = [email protected]
[color]
ui = auto
[core]
quotepath = false
editor = emacsclient
autocrlf = false
[alias]
@koko-u
koko-u / .gemrc
Created June 18, 2011 08:35
デフォルトで --no-rdoc --no-ri する
gem: --no-ri --no-rdoc
static VALUE
rb_str_each_line(int argc, VALUE *argv, VALUE str)
{
rb_encoding *enc;
VALUE rs;
unsigned int newline;
const char *p, *pend, *s, *ptr;
long len, rslen;
VALUE line;
int n;
@koko-u
koko-u / freq_gem
Created January 29, 2012 03:36
frequently used gems in rails app
gem 'i18n_generators'
group :development, :test do
gem 'capybara'
gem 'rspec-rails'
gem 'spork'
gem 'watchr'
gem 'factory_girl_rails'
gem 'timecop'
gem 'fuubar'