Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / td2sec.php
Created October 2, 2008 20:27
Convert RFC1123-style time differences to N-seconds (PHP)
/**
* Convert RFC1123-style time differences to N-seconds
*
* If unixtime is given, convert first it to RFC1123-style time
* differences by date( "O" ).
*
* @since 2008-10-03
* @param string
* @return int
*/
@wtnabe
wtnabe / feedcreator.class.php.diff
Created November 23, 2008 08:08
feedcreator multibyte patch
Index: include/feedcreator.class.php
===================================================================
--- include/feedcreator.class.php (revision 17)
+++ include/feedcreator.class.php (working copy)
@@ -521,6 +521,9 @@
* @return string the truncated string
*/
function iTrunc($string, $length) {
+ if (extension_loaded('mbstring')) {
+ return FeedCreator::iTrunc_mb($string, $length);
@wtnabe
wtnabe / icat.rb
Created November 24, 2008 14:48
"icat", just cat ical data written in Ruby
#! /usr/bin/env ruby
require 'rubygems'
require 'vpim/icalendar'
require 'open-uri'
require 'optparse'
$KCODE = 'u'
class Icat
def initialize
@wtnabe
wtnabe / rest_client.rb.diff
Created November 28, 2008 03:33
A rest-client's patch for zero byte response body. Now no longer required.
index 1bf1d10..3716dee 100644
--- a/lib/rest_client.rb
+++ b/lib/rest_client.rb
@@ -228,7 +228,7 @@ module RestClient
end
def response_log(res)
- "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{res.body.size} bytes"
+ "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{res.body ? res.body.size : 0} bytes"
end
@wtnabe
wtnabe / raw.inc.php
Created December 17, 2008 02:09
PukiWiki で page の source をそのまま返す raw plugin
<?php
/**
* page の内容をそのまま HTML に整形せずに返す
*
* @since 2008-12-17
*/
function plugin_raw_action() {
global $vars, $_title_invalidwn, $_msg_invalidiwn;
$page = isset( $vars['page'] ) ? $vars['page'] : '';
@wtnabe
wtnabe / default_task.rake
Created January 5, 2009 03:01
A Rake's default task, for simply listing tasks
# -*- mode: ruby -*-
task :default do
sh 'rake -s -T', :verbose => false
end
@wtnabe
wtnabe / array_utils.php
Created February 24, 2009 06:33
Some useful array functions for PHP
<?php
/**
* Array Utils
*
* @since 2009-02-23
*/
if ( !function_exists( 'array_at' ) ) {
/**
* array の中の index の位置の値を返す
# -*- coding: utf-8 -*-
=begin
irb(main):001:0> Size.amount( '2GB' )
=> 2000000000.0
irb(main):002:0> Size.amount( '2GiB' )
=> 2147483648.0
LICENSE : two-clause BSD
@wtnabe
wtnabe / array_classify.rb
Created March 1, 2009 07:40
Array#classify for String elements using Regexp
# -*- coding: utf-8 -*-
class Array
#
# classift( /()/ )
#
# [
# [grouped by same \1],
# [grouped by same \1],
# [grouped by same \1],
=begin
Mechanize debug 用の wrapper
LICENSE : two-clause BSD
=end
def get( uri )
if ( @agent.log )