Skip to content

Instantly share code, notes, and snippets.

@masaki
masaki / dbi_sample.rb
Created December 11, 2011 12:25
MySQL Casual 2011 sample
require 'rubygems'
require 'dbi'
require 'pp'
dbh = DBI.connect('dbi:mysql:database=test;host=localhost', 'test', 'test')
pp dbh.select_one('SELECT VERSION()')
sth = dbh.prepare('SELECT * FROM mysql_casual WHERE name = ?')
sth.execute('ikasam_a')
while row = sth.fetch_hash do
@masaki
masaki / Makefile.PL
Created December 5, 2011 05:47
Module::Install on Module::Setup
use inc::Module::Install;
use Module::Install::AuthorTests;
use Module::Install::Repository;
use Module::Install::ReadmePodFromPod;
name '[% dist %]';
license 'perl';
all_from 'lib/[% module_unix_path %].pm';
# requires '';
@masaki
masaki / .proverc.ci
Created November 24, 2011 09:46
.proverc for Jenkins
-Ilib -It/lib
-MTest::Name::FromLine
--timer --verbose
--nocolor
--formatter=TAP::Formatter::JUnit
--recurse
@masaki
masaki / Descriptive.pm
Created November 15, 2011 06:21
Test::More::Descriptive - Test::More + describe/context/it
package Test::More::Descriptive;
use strict;
use warnings;
use Exporter 'import';
use Test::More ();
BEGIN {
*describe = *context = *it = \&Test::More::subtest;
}
@masaki
masaki / vmclone.sh
Created October 10, 2011 17:18
VMware ESXi 4.0 VM Cloning script w/ SSH enabled
#!/bin/sh
# usage: vmclone.sh SOURCE TARGET
SOURCE_NAME=$1
TARGET_NAME=$2
VMSTORE=/vmfs/volumes/datastore1
VMID=`vim-cmd vmsvc/getallvms | awk '/'"$SOURCE_NAME"'/ {print $1;}'`
SOURCE_DIR=$VMSTORE/$SOURCE_NAME
@masaki
masaki / gist:1238005
Created September 23, 2011 17:52
PhantomJS on CentOS-5
# SEE: http://d.hatena.ne.jp/shim0mura/20110730/1312046133
# SEE: https://gist.github.com/1031961
# SEE: http://atrpms.net/documentation/install/
# 1. prepare
$ cat /etc/yum.repos.d/atrpms.repo
[atrpms-stable]
name=ATrpms RHEL5 stable
baseurl=http://dl.atrpms.net/el5-$basearch/atrpms/stable/
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
@masaki
masaki / gist:1176646
Created August 28, 2011 13:09
install blockdiag at CentOS 5.x
$ sudo yum install freetype freetype-devel libpng libpng-devel # for PIL
$ sudo yum install python-setuptools fonts-japanese
$ sudo easy_install PIL funcparserlib
$ sudo easy_install http://pypi.python.org/packages/source/w/webcolors/webcolors-1.3.1.tar.gz
$ sudo easy_install blockdiag nwdiag actdiag seqdiag
@masaki
masaki / gist:1176638
Created August 28, 2011 12:59
direct easy_install
$ sudo easy_install webcolors Searching for webcolors
Reading http://cheeseshop.python.org/pypi/webcolors/
Reading http://www.bitbucket.org/ubernostrum/webcolors/overview/
error: Download error: (-2, 'Name or service not known')
exit 1
$ sudo easy_install http://pypi.python.org/packages/source/w/webcolors/webcolors-1.3.1.tar.gz
Downloading http://pypi.python.org/packages/source/w/webcolors/webcolors-1.3.1.tar.gz
Processing webcolors-1.3.1.tar.gz
Running webcolors-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-HXFg3s/webcolors-1.3.1/egg-dist-tmp-hw4BbL
@masaki
masaki / setup.rake
Created July 27, 2011 00:15
create Rails config files as Rake task
# -*- encoding: utf-8 -*-
namespace :setup do
def copy_config(options = {})
Dir["#{RAILS_ROOT}/**/*.sample", "#{RAILS_ROOT}/**/*.example"].each do |source|
target = source.sub(/\.(ex|s)ample$/, '')
if options[:force] or not File.exist?(target)
require 'fileutils'
puts "Create config file '#{target}' from '#{source}'"
FileUtils.copy_file source, target
@masaki
masaki / rubygems-1.8.5-no_proxy.patch
Created July 20, 2011 12:15
RubyGems NO_PROXY auto-detection without http_configuration gem
--- rubygems-1.8.5/lib/rubygems/remote_fetcher.rb.orig 2011-07-20 00:28:13.000000000 +0900
+++ rubygems-1.8.5/lib/rubygems/remote_fetcher.rb 2011-07-20 01:09:59.000000000 +0900
@@ -69,6 +69,7 @@
when URI::HTTP then proxy
else URI.parse(proxy)
end
+ @no_proxy = (ENV['NO_PROXY'] || ENV['no_proxy'] || 'localhost, 127.0.0.1').split(/\s*,\s*/)
@user_agent = user_agent
end