Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / database.php
Created March 4, 2009 10:49
force switch database configuration for sad CakePHP 1.1.x
/**
* A Bad Knowhow for CakePHP 1.1.x
*
* force rewriting `default' setting
* because libs/session.php has hard-coded `default' !
*/
class DATABASE_CONFIG {
var $default = array( 'driver' => 'XXXXX',
'connect' => 'XXXXX',
'host' => 'XXXXX',
@wtnabe
wtnabe / do_with_retry.rb
Created March 5, 2009 05:39
A retrier for poor quality network and servers
#
# always retry
#
# ex)
# do_with_retry( 'dns' ) { Resolv.getaddress( 'example.com' ) }
#
def do_with_retry( name, &block )
times = RETRY_LIMIT
begin
block.call
@wtnabe
wtnabe / ezdebug-mechanize.rb
Created March 9, 2009 06:48
A subclass of Ruby's Mechanize for easy and happy debugging
# -*- coding: utf-8 -*-
=begin
agent = EzDebug_Mechanize.new( :debug => true,
:page_dir => /path/to/dir ) { |a|
a.log = Logger( '/path/to/logfile' )
a.log.level = Logger::DEBUG
}
@wtnabe
wtnabe / ssh_and_su_example.rb
Created March 15, 2009 09:47
"ssh and su" automation sample with Ruby and except
# -*- coding: utf-8 -*-
require 'pty'
require 'expect'
=begin
ssh & su example for expect.rb
variables
@wtnabe
wtnabe / pear-support-capfile.rb
Created March 16, 2009 08:20
uribase pear package manager written in capistrano
# -*- mode: ruby; coding: utf-8 -*-
require 'hpricot'
require 'open-uri'
=begin
required configuration
set :package, {
@wtnabe
wtnabe / simple-diff-lcs.rb
Created April 10, 2009 10:44
how to use Diff::LCS most quickly
Object::Diff::LCS.diff( lines_array, lines_array ).each { |d|
d.each { |c|
puts c.to_a.to_s
}
}
@wtnabe
wtnabe / alarm-sample.ics
Created April 22, 2009 09:22
iCal でアラームを記述する基本形
BEGIN:VEVENT
...
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-P1D
DESCRIPTION:イベント
ACTION:DISPLAY
END:VALARM
END:VEVENT
COMMENT:iCalのアラームの基本形
@wtnabe
wtnabe / except-with-rake.rb
Created May 16, 2009 12:19
A sample script of disappearing Exception message in Rake
class FooExcept < StandardError; end
task :default do
raise FooExcept, 'bar'
end
@wtnabe
wtnabe / calendar_viewer.inc.php.diff
Created May 26, 2009 01:01
PukiWiki の calendar_view plugin の中で block level plugin を無視するパッチ
diff --git a/plugin/calendar_viewer.inc.php b/plugin/calendar_viewer.inc.php
index cafc33b..874d899 100644
--- a/plugin/calendar_viewer.inc.php
+++ b/plugin/calendar_viewer.inc.php
@@ -68,6 +68,7 @@ function plugin_calendar_viewer_convert()
$limit_page = 0; // サーチするページ数
$mode = 'past'; // 動作モード
$date_sep = '-'; // 日付のセパレータ calendar2なら '-', calendarなら ''
+ $ignore_blockplugin = false;
@wtnabe
wtnabe / vcat.awk
Created June 8, 2009 07:57
vertical 'cat' command known as a part of 'paste'
#
# Usage: vcat [-v ofs=<OFS>] <file1> [file2] ...
#
# Cannot specify field of file. Use cut command instead.
#
BEGIN {
if ( ofs ) {
OFS = ofs
} else {