Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / README.md
Created December 15, 2010 08:42
import seed data from .csv or .yml for Rails 2.3.4+

Rails SeedImporter

  1. Put this code at #{Rails.root}/db/seeds.rb
  2. type rake db:setup

Limitation

It supports only `id' primary key.

@wtnabe
wtnabe / class_by_poc.rb
Created December 20, 2010 13:25
fabrication with faker and forgery
class Company
def initialize
@name = nil
@addr = nil
@url = nil
@tel = nil
@email = nil
@foundation = nil
end
@wtnabe
wtnabe / cleanup_ssh
Created January 3, 2011 23:56
clean up your uncontrollable ssh sessions ( also live sessions X-)
#! /bin/sh
#
# clean up your uncontrollable ssh sessions
#
ps a | awk '$5 ~ /^ssh/ {print $1}' | xargs kill -KILL
find ~/.ssh/ -name 'master-*' | xargs rm
@wtnabe
wtnabe / gist:785582
Created January 19, 2011 02:28
set $KCODE if Ruby < 1.9
$KCODE='u' unless defined? ::Encoding
@wtnabe
wtnabe / gist:786125
Created January 19, 2011 12:50
(no longer required) monkey patch for file uploading failure with Rails 3.0.3 + jpmobile 0.1.4 env
module ActionDispatch
module Http
class UploadedFile
def to_param
self
end
end
end
end
@wtnabe
wtnabe / dummy_model.rb
Created January 25, 2011 01:08
validates with class methods ( validates_* なヘルパーはクラスメソッドです!)
# -*- mode: ruby -*-
class Klass < ActiveRecord::Base
# "undefined ..."
validates_inclusion_of :in => values
# success !
validates_inclusion_of :in => self.values
# cannot be called
@wtnabe
wtnabe / README.md
Created February 2, 2011 23:04
easy fabricator command for Ruby's fabrication library

Usage

Usage: easy_fabricator [options] FABRICATOR
    -n, --num NUM ( default 1 )
    -y, --output-yaml
    -c, --output-csv ( default )

Fabricator

@wtnabe
wtnabe / application.js
Created March 6, 2011 08:29
My first javascript routing with jQuery-Router & LABjs
jQuery( function($) {
$.route(
{
path: /^\/$/,
func: function() {
$LAB.script('/javascripts/console_hello.js');
}
},
{
path: /^\/hello/,
@wtnabe
wtnabe / in.rb
Created March 7, 2011 14:57
`in' form generator for Rails Model
#
# [Param] String column
# [Param] Array items
# [Return] String
#
def self.in( column, items )
if ( items.respond_to? :map and items.size > 0 )
sprintf( "#{column} in ( %s )",
items.map { |e|
( e.is_a? String ) ? sanitize(e) : e
@wtnabe
wtnabe / git.rake
Created March 8, 2011 06:22
git task for remember `git add' (Put this to Rails.root/lib/tasks/git.rake and type `rake -T')
namespace :git do
desc "list git-untracked files"
task :untracked do
sh 'git ls-files -o --exclude-from=.gitignore'
end
end