Skip to content

Instantly share code, notes, and snippets.

@marugoshi
marugoshi / .watchr
Created February 9, 2012 09:51
My .watchr
def run(cmd)
`#{cmd}`
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
@marugoshi
marugoshi / url.rb
Created February 9, 2012 06:30
Custom url validation for Rails3
# -*- coding: utf-8 -*-
class UrlValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
uri = ::Addressable::URI.parse(value)
unless ["http", "https", "ftp"].include?(uri.scheme)
raise ::Addressable::URI::InvalidURIError
end
rescue ::Addressable::URI::InvalidURIError
record.errors[attribute] << "Invalid URL"
@marugoshi
marugoshi / gist:1306012
Created October 22, 2011 13:31
Sublime Text 2 Setting
{
"font_face": "consolas",
"font_size": 12,
"tab_size": 2,
"translate_tabs_to_spaces": true
}
@marugoshi
marugoshi / ramdisk.sh
Created October 7, 2011 19:52
To Save MacBookAir SSD
#!/bin/sh
SIZE=262144
MOUNT_POINT=/Volumes/ramdisk
RAM_DISK=`hdid -nomount ram://$SIZE`
newfs_hfs -v ramdisk $RAM_DISK
mkdir -p $MOUNT_POINT
mount -t hfs $RAM_DISK $MOUNT_POINT
chmod 0777 $MOUNT_POINT
@marugoshi
marugoshi / gist:1258003
Created October 2, 2011 21:41
pow install script
#!/bin/sh
# W
# R RW W.
# RW::::RW DR::R
# :RRRRRWWWWRt:::::::RRR::::::E jR
# R.::::::::::::::::::::::::::Ri jiR:::R
# R:::::::.RERRRRWWRERR,::::::Efi:::::::R GjRRR Rj
# R::::::.R R:::::::::::::;G RRj WWR RjRRRRj
# Rt::::WR RRWR R::::::::::::::::fWR::R; WRW RW R
# WWWWRR:::EWR E::W WRRW:::EWRRR::::::::: RRED WR RRW RR
@marugoshi
marugoshi / spork.rake
Created March 14, 2011 15:15
Start, stop, restart spork rake task
namespace :spork do
desc "start spork in background"
task :start do
sh %{spork &}
end
desc "stop spork"
task :stop do
Process.kill(:TERM, `ps -ef | grep spork | grep -v grep | awk '{ print $2 }'`.to_i)
end
@marugoshi
marugoshi / convert.rake
Created March 3, 2011 14:53
Export MySQL data to sql file in order to import to PostgreSQL task.
#
# Export development database(MySQL) data to sql file in order to
# import to production database(PostgreSQL) task specialized radiant.
#
# WARGNING: It should be configured database.yml also created databases
# both development and production and runned db:migrate before run tasks.
# MySQL database is already imported is needed.
#
# usage: rake db:convert:execute
#
ja:
# extract from activesupport
date:
formats:
default: "%Y/%m/%d"
short: "%m/%d"
long: "%Y年%m月%d日(%a)"
day_names: [日曜日, 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日]
abbr_day_names: [日, 月, 火, 水, 木, 金, 土]
module Ext
module Object
def self.included(base)
base.class_eval do
include InstanceMethods
end
end
module InstanceMethods
def current_method