Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / td2sec.php
Created Oct 2, 2008
Convert RFC1123-style time differences to N-seconds (PHP)
View td2sec.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 Nov 23, 2008
feedcreator multibyte patch
View feedcreator.class.php.diff
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 Nov 24, 2008
"icat", just cat ical data written in Ruby
View icat.rb
#! /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 Nov 28, 2008
A rest-client's patch for zero byte response body. Now no longer required.
View rest_client.rb.diff
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 Dec 17, 2008
PukiWiki で page の source をそのまま返す raw plugin
View raw.inc.php
<?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 Jan 5, 2009
A Rake's default task, for simply listing tasks
View default_task.rake
# -*- mode: ruby -*-
task :default do
sh 'rake -s -T', :verbose => false
end
@wtnabe
wtnabe / array_utils.php
Created Feb 24, 2009
Some useful array functions for PHP
View array_utils.php
<?php
/**
* Array Utils
*
* @since 2009-02-23
*/
if ( !function_exists( 'array_at' ) ) {
/**
* array の中の index の位置の値を返す
View size.rb
# -*- 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 Mar 1, 2009
Array#classify for String elements using Regexp
View array_classify.rb
# -*- coding: utf-8 -*-
class Array
#
# classift( /()/ )
#
# [
# [grouped by same \1],
# [grouped by same \1],
# [grouped by same \1],
View mechanize_assist.rb
=begin
Mechanize debug 用の wrapper
LICENSE : two-clause BSD
=end
def get( uri )
if ( @agent.log )