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
# This module offers the way to get session_id from HTTP_X_SID | |
# in the request headers for Rack application. | |
# | |
# This is only work memcache and dalli | |
# (Rack::Session::Cookie implements 'extract_session_id' by itself.) | |
# Put this file in config/initializers when used with Rails. | |
# | |
# I don't know why this module exists because the default way is | |
# using cookies, but cookie is even put in HTTP Request and response | |
# headers too. |
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
class Person | |
def initialize(args) | |
args.each do |key, value| | |
self.class.send(:attr_accessor, :"#{key}") unless instance_variables.include?(:"@#{key}") | |
instance_variable_set(:"@#{key}", value) | |
end | |
end | |
def self.undef_has_a_var_which_begins_with(var) | |
method_name = "has_a_#{var}_which_begins_with?" |
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
# FIXME | |
# Is there more beautiful expression of lazy evaluation for expect{} and DRY? | |
# | |
describe ItemsController do | |
describe "POST 'create'" do | |
before do | |
@action = lambda { post :create, :name => 'foo' } | |
end | |
describe "response" do |
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
# I'm wondering which is better | |
# ex1: in it ".." block | |
describe "#create" do | |
it "should create an item" do | |
expect { Item.create(:name => 'foo') }.to change{Item.count}.by(1) | |
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 RandomString | |
# chars example is ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a | |
def self.random_of(chars, length=10) | |
Array.new(length){chars[rand(chars.size)]}.join | |
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 StringCtypt | |
class String | |
def crypt | |
return Digest::SHA1.hexdigest(self) | |
end | |
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
# | |
# changed font for Japanese environment | |
# Probably it is OK to add 'font_name = "..."' in 'style "theme-default"' block. | |
# | |
include "/Library/Frameworks/Mono.framework/Versions/Current/share/themes/Clearlooks/gtk-2.0/gtkrc" | |
#gtk-icon-theme-name = "OSX" | |
gtk-icon-theme-name = "Tango" | |
gtk_color_scheme = "fg_color:#222\nbg_color:#e6e6e6\nbase_color:#f9f9f9\ntext_color:#222\nselected_bg_color:#788ab0\nselected_fg_color:#fff" | |
gtk-menu-popup-delay = 1 | |
gtk-button-images = 0 |
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
class Integer | |
def to_comma_separated() | |
self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse | |
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
alter table foo_table add index(column1); | |
show indexes from foo_table; |
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
#!/bin/bash | |
aptitude install ibus-gtk3 |
OlderNewer