Skip to content

Instantly share code, notes, and snippets.

View fujimura's full-sized avatar

Daisuke Fujimura fujimura

View GitHub Profile
@fujimura
fujimura / parallel_map.rb
Created August 18, 2011 03:16
parallel map
module Enumerable
def parallel_map(&block)
threads = []
result = {}
self.each_with_index do |a, i|
threads << Thread.new do
result[i] = [a].map(&block).first
end
end
@fujimura
fujimura / bundle_exec_is_fast
Created August 19, 2011 02:02
bundle exec is fast
$ time bundle exec rspec spec/fb_graph/rails/authentication_spec.rb ~/fb_graph-rails
........................
Finished in 0.49638 seconds
24 examples, 0 failures
bundle exec rspec spec/fb_graph/rails/authentication_spec.rb 3.85s user 0.86s system 98% cpu 4.775 total
$ time rspec spec/fb_graph/rails/authentication_spec.rb ~/fb_graph-rails
........................
@fujimura
fujimura / vim.rb
Created September 8, 2011 04:44 — forked from JosephKu/vim.rb
Vim formula for HomeBrew
#/usr/local/Library/Formula/vim.rb
#
# Vim formula for HomeBrew
#
# Written by Joseph Ku <[email protected]>
# All right reserved.
require 'formula'
class Vim < Formula
@fujimura
fujimura / vim.rb
Created September 8, 2011 04:44 — forked from JosephKu/vim.rb
Vim formula for HomeBrew
#/usr/local/Library/Formula/vim.rb
#
# Vim formula for HomeBrew
#
# Written by Joseph Ku <[email protected]>
# All right reserved.
require 'formula'
class Vim < Formula
# -*- encoding: utf-8 -*-
require 'tempfile'
module Editable
# Edit self by $EDITOR
#
def edit!
temp = Tempfile.new(self.object_id.to_s)
# From http://d.hatena.ne.jp/mollifier/20090814/p1
zstyle ':vcs_info:*' formats '%b'
zstyle ':vcs_info:*' actionformats '%b|%a'
ZSHFG=`expr $RANDOM / 128`
precmd () {
psvar=()
LANG=en_US.UTF-8 vcs_info
[[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_"
if [ $ZSHFG -ge 250 ]
@fujimura
fujimura / gist:1247633
Created September 28, 2011 10:49
users
ruby-1.9.2-p290 :037 > value['warden.user.default.key'].first => User(id: integer, email: string, password_digest: string, read_tos_at: datetime, deleted_at: datetime, created_at: datetime, updated_at: datetime)
ruby-1.9.2-p290 :038 > User => User(id: integer, email: string, password_digest: string, read_tos_at: datetime, deleted_at: datetime, created_at: datetime, updated_at: datetime)
ruby-1.9.2-p290 :039 > value['warden.user.default.key'].first == User
=> false ruby-1.9.2-p290 :040 >
# From http://d.hatena.ne.jp/mollifier/20090814/p1
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '%b'
zstyle ':vcs_info:*' actionformats '%b|%a'
# Set initial color
ZSHFG=`expr $RANDOM / 128`
precmd () {
# Set git info into 1v
# encoding: utf-8
count = 0
# getsでターミナルで打った文字が取れます
while number = gets
# getsは文字で受け取るので、to_iで数字に変換
count = count + number.to_i
if count >= 1000
puts '1000 over'
# -*- encoding: utf-8 -*-
name = "My name is Fujimura, I was born in Kawasaki city"
# ここで名前を変更して、name変数を上書き
name = name.sub("Fujimura", "Chikuwa")
# ここで街を変更、name変数を上書き
name = name.sub("Kawasaki", "Kyoto")