Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby -wKU
def ip_route_match(command, regex)
command.split("\n").select { |l| l =~ regex }.first.to_s[/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/] || '0.0.0.0'
end
c = '10.128.0.0/24 dev eth1 proto kernel scope link src 10.128.0.48
127.0.0.0/8 dev lo scope link
default via 10.128.0.254 dev eth1'
# c = %x{/sbin/ip route list match #{ip}}
@samsouder
samsouder / debug_backtrace_format.php
Created September 18, 2009 15:12
A little PHP function to get a succinct string of function backtraces
<?php
// A little PHP function to get a succinct string of function backtraces.
function debug_backtrace_format()
{
$bt = array_slice(debug_backtrace(), 1); // shift off the call to debug_backtrace_format()
return join(', ', array_map(create_function('$a', 'return $a["function"] ."() (". $a["file"] .":". $a["line"] .")";'), $bt));
}
function test()
@samsouder
samsouder / gzencode.sh
Created March 31, 2009 20:09
Output a gzip-encoded stream for any standard input given.
#!/usr/bin/env bash
php -r "echo gzencode(file_get_contents('php://stdin'));"
@samsouder
samsouder / nokogiri_builder_test.rb
Created March 11, 2009 18:10
For some reason, I can't access a class variable inside a Nokogiri block like I can inside Builder blocks.
require 'rubygems'
require 'builder' # 2.1.2
require 'nokogiri' # 1.2.1
@testing = { :item1 => 'value1', :item2 => 'value2', :item3 => 'value3' }
def nokogiri
Nokogiri::XML::Builder.new {
root {
items {