Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / turnoff_buffering.php
Created February 8, 2010 23:57
disable PHP's output buffering
/**
* turn off output buffering cleanly
*/
function turnoff_buffering() {
while ( ob_get_level() > 0 ) {
ob_end_clean();
}
}
@wtnabe
wtnabe / file2array.php
Created March 20, 2010 03:26
simple converter from file to array with PHP
<?php
function file2array( $file ) {
return file_exists( $file )
? array_filter( array_map( 'chop', file( $file ) ) )
: array();
}
@wtnabe
wtnabe / test_suite_for_simpletest.php
Created April 4, 2010 13:11
A Test Suite for SimpleTest 1.0.0 and 'exit status'
<?php
class AllTests extends GroupTest {
function AllTests() {
$this->add( realpath('.') );
}
function add( $dir = null ) {
if ( $dh = opendir( $dir ) ) {
while ( ($e = readdir( $dh )) !== false ) {
$path = $dir.DIRECTORY_SEPARATOR.$e;
@wtnabe
wtnabe / fold.php
Created April 12, 2010 10:03
A simple folding written in PHP for mainly Japanese
<?php
/**
* folding for mainly Japanese
*
* @license Two-clause BSD
*/
/**
* fold
*
@wtnabe
wtnabe / ping_and_growl.rb
Created June 7, 2010 10:20
simple network monitor with ping and growl
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'logger'
=begin
WHATIS
* ping monitoring once every 30 secs
@wtnabe
wtnabe / skype_html_log_grep.rb
Created June 13, 2010 15:51
A grep for Skype HTML log written in Ruby
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'optparse'
require 'rubygems' unless defined? Gem
require 'nokogiri'
require 'highline'
$KCODE = 'u' unless defined? Encode
class Skype_Html_Log_Parser
@wtnabe
wtnabe / gist:500122
Created July 30, 2010 08:01
httpd.conf for blocking access by IP addr ( not HostName )
deny access by IP addr
<VirtualHost 192.168.0.1:80>
ServerName 192.168.0.1
<Location />
Deny from all
</Location>
</VirtualHost>
@wtnabe
wtnabe / gist:502106
Created July 31, 2010 12:08
comparison bzip2 and pbzip2 with unix pipeline
$ time find pctraining | cpio -o | bzip2 > pctraining.cpio.bz2
find pctraining 0.00s user 0.01s system 59% cpu 0.025 total
cpio -o 0.11s user 0.20s system 5% cpu 5.455 total
bzip2 > pctraining.cpio.bz2 5.06s user 0.08s system 91% cpu 5.604 total
$ time find pctraining | cpio -o | pbzip2 > pctraining.cpio.pbz2
find pctraining 0.00s user 0.01s system 52% cpu 0.026 total
cpio -o 0.10s user 0.19s system 15% cpu 1.940 total
pbzip2 > pctraining.cpio.pbz2 3.64s user 0.20s system 160% cpu 2.397 total
@wtnabe
wtnabe / mime.conf.diff
Created August 3, 2010 02:03
prep of Debian's Apache2 for forcing browse .txt.gz, .html.gz, ...
@@ -25,7 +25,7 @@
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
-AddType application/x-gzip .gz .tgz
+#AddType application/x-gzip .gz .tgz
AddType application/x-bzip2 .bz2
#
@wtnabe
wtnabe / arhive-test.sh
Created August 7, 2010 02:31
appending gziped file to tar archive
#! /bin/sh
ARCHIVE=logs.gz.tar
#
# create files
#
echo "create dummy files ..."
for i in `awk '
BEGIN {