Skip to content

Instantly share code, notes, and snippets.

@a2ikm
a2ikm / reinstall-rdoc-data-for-ruby-192.sh
Created August 1, 2011 06:11
“File not found: lib” error while installing Rails 3.0.9 for MacOSX, RVM, Ruby1.9.2
# http://vermelho.jugem.jp/?eid=131
gem install rdoc-data
cp -pR $rvm_path/gems/ruby-1.9.2-p290/gems/rdoc-data-2.5.3/data/1.9.1 $rvm_path/gems/ruby-1.9.2-p290/gems/rdoc-data-2.5.3/data/1.9.2
rdoc-data --install
gem rdoc --all --overwrite
mkdir $rvm_path/gems/ruby-1.9.2-p290/gems/rails-3.0.9/lib
gem install rails
@a2ikm
a2ikm / ts.pm
Created August 4, 2011 13:54
add modified timestamps to img tag's src and link tag's href
package MyApp::View::Plugin::Ts;
=head1 MyApp::View::Plugin::Ts
imgタグのsrc属性値やlinkタグのhref属性値に対象のファイルの更新時刻を付加することで
ファイルの更新が行われた際にブラウザがキャッシュを捨てて再度リクエストすることを促すためのTTプラグイン
=cut
use strict;
@a2ikm
a2ikm / rd.sh
Created August 12, 2011 07:02
remote diff
#
# Show differences between local and remote files.
# Compared files must be at same path.
#
# Usage: rd FILENAME REMOTE_HOST
#
rd() {
FILE=$1
REMOTE=$2
@a2ikm
a2ikm / object_id.rb
Created August 15, 2011 00:43
infinite loop of Object#object_id
x = nil # any object is OK.
loop { puts x = x.object_id }
@a2ikm
a2ikm / rd.pl
Created August 18, 2011 15:21
remote diff for servers on the same directory trees.
#!/usr/bin/env perl
my $name = $ARGV[0];
chomp $name;
my $remote = $ARGV[1];
chomp $remote;
my $path;
if ($name =~ /^//) {
@a2ikm
a2ikm / commands.txt
Created August 24, 2011 13:48
rsync and Filesys::Notify::Simple are imcompatible
# [window1] start fsnotify.pl
$ cd ~/tmp
$ ... save fsnotify.pl here ...
$ perl fsnotify.pl [~ 22:39]
Watching tmp for file updates.
# [window2] rsync a file to the directory
$ rsync /somewhere/bar.txt ~/tmp
@a2ikm
a2ikm / nested_const.rb
Created September 9, 2011 07:06
Get or set nested constant
#!/usr/bin/ruby
class Object
# copied from http://blog.udzura.jp/2010/03/08/petit-hacking-about-const_get/
def self.nested_const_get(name)
stack = (name.is_a?(Array)) ? name : name.to_s.split("::")
klass = Object
while const = stack.shift
klass = klass.const_get(const)
end
@a2ikm
a2ikm / rvmrc.rb
Created September 11, 2011 13:26
generate .rvmrc
#!/usr/bin/env ruby
require 'rubygems'
require 'micro-optparse'
options = Parser.new { |p|
p.banner = "Generate .rvmrc file."
p.version = "0.1"
p.option :ruby, "Version of Ruby interpreter installed with RVM", :default => RUBY_VERSION
p.option :gemset, "Name of RVM gemset", :default => File.basename(`pwd`.strip)
@a2ikm
a2ikm / gist:1264159
Created October 5, 2011 10:44
box-ordinal-group
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>さんぷる</title>
<style type="text/css">
.item {
display: -moz-box;
display: -webkit-box;
display: box;
@a2ikm
a2ikm / camelize.rb
Created October 24, 2011 02:37
camelize
class String
def camelize
split("_").map { |part|
part[0] = part[0].upcase
part
}.join
end
end