Skip to content

Instantly share code, notes, and snippets.

View gderosa's full-sized avatar

Guido De Rosa gderosa

View GitHub Profile
SELECT t2.* FROM ((SELECT username FROM radcheck GROUP BY username LIMIT 4) AS t1) JOIN (radcheck as t2) ON t1.username = t2.username;
md5_w_salt = Base64.encode64(Digest::MD5.digest('saltedpass' + 'salt') + 'salt').chomp!
random_binary_str = (Array.new(16){ rand(0x100) }).pack('c*')
@gderosa
gderosa / finalizer.rb
Created October 22, 2010 09:54
Spawn children and/or take other resources? Clean it all when out of scope!
# Use ObjectSpace.define_finalizer, as
# inspired by the Ruby std library (tmpfile.rb)
class C
def initialize
@child_pid = fork do
sleep 1000
end
Process.detach(@child_pid) if @child_pid
ObjectSpace.define_finalizer self, Killer.new(@child_pid)
end
require 'pp'
class Object
def deep_map_values(&block)
if respond_to? :each_pair
out = {}
each_pair do |k, v|
out[k] = v.deep_map_values(&block)
end
require 'ipaddr'
require 'pp'
module ConfigFiles
class Parameter
attr_accessor :name, :properties
def is(*args)
@properties = args if args.length > 0
end
# parse dar -l
#
# list directory
p Time.now
IO.popen('dar -l files -K "bf:o"', 'r').each_line do |line|
line.force_encoding 'ASCII-8BIT'
if line =~ /^(\[[^\[\]]+\])\s+(\[[^\[\]]+\])\s+([-\w])([-\w]{9})\s+(\S+)\s+(\S+)\s+(\d+)\s+(\w{3} \w{3} \d+ \d\d:\d\d:\d\d \d\d\d\d)\s+(\S.*\S)\s*$/
saved, comp, type, perms, u, g, size, mtime, path =