Skip to content

Instantly share code, notes, and snippets.

@sousk
sousk / snippet.rb
Created June 11, 2009 07:00
split large log into files named by the date (like May_11.log)
#!/usr/bin/env ruby
#'$_ = $_.match(/^([A-Z][a-z]+)\s+([0-9]+)/) ? "#{$1}_#{$2}\n" : ""' head.log > date.log
class FileSplitter
attr_accessor :read_from, :logdir
def initialize(args)
@read_from, @logdir = args
@cur_m, @cur_d, @f = nil
@sousk
sousk / snippet.rb
Created June 11, 2009 07:34
snip out large text file with regexp
#!/usr/bin/env ruby
path, from, to = $*
unless path && from && to
puts <<-__DESCRIPTION__
./echo_between.rb file_path "from" "to"
snips large text file
command starts to print lines when matched "from"
@sousk
sousk / snippet.rb
Created June 16, 2009 00:33
weby: make current directory accessible via HTTP
#!/usr/bin/env ruby
require 'webrick'
require 'optparse'
include WEBrick
OPTIONS = {
# :BindingAddress => '0.0.0.0',
:Port => 3000,
require 'rubygems'
class Trac
def initialize(url)
@url = url
end
def newticket
@url + '/newticket'
end
function not_empty(expr, msg) {
ok(function() {
if (! expr) {
return false;
}
// has length
else if (typeof expr['length'] == 'number') {
return expr.length > 0;
}
else {
@sousk
sousk / userjs - showing hantena bookmark comment on the page
Created August 12, 2009 02:23
userjs - showing hantena bookmark comment on the page
// ==UserScript==
// @name ShowHatenaBookmarkComment
// @namespace userjs.phphp.net
// @description build hatena bookmark comments
// @include http://*
// ==/UserScript==
/* Original Script: Hatena Bookmark Comments Viewer
* <http://www.ne.jp/asahi/nanto/moon/>
* <http://worris.sakura.ne.jp/hbcview.html>
@sousk
sousk / gist:167024
Created August 13, 2009 06:43
reload firefox v3.5
ps -xc|grep -sqi firefox && osascript <<'APPLESCRIPT'
tell application "Firefox" to activate
tell application "System Events"
if UI elements enabled then
keystroke "r" using command down
-- Fails if System Preferences > Universal access > "Enable access for assistive devices" is not on
else
-- Fails if Firefox is set to open URLs from external apps in new tabs.
-- tell app "Firefox" to Get URL "JavaScript:window.location.reload();" inside window 1
tell application "Firefox" to get URL "JavaScript:window.location.reload();"
@sousk
sousk / MockObject.class.php
Created November 2, 2009 06:14
a mock object lib for symfony/doctest
<?php
/**
* #test prepare for the test
* <code>
* class User {};
* function setup() {
* MockObject::setFixturePath(sfConfig::get('sf_test_dir') .'/fixtures/test_mock_object.yml', true);
* }
*
* </code>
@sousk
sousk / docTestHelper.php
Created November 8, 2009 03:01
php doctest helper: getting an authenticated user instance
/**
* #test test_user
* <code>
* #diag('expect error');
* try {
* $u = test_user('peko');
* #fail('should raise error');
* }
* catch(Exception $e) {
* #ok($e,$e->getMessage());
public static function getCriteria($c=null)
{
if (! $c) {
$c = new Criteria;
}
return $c;
}
public static function retrieveBy($col, $value)
{