This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
OPS = {} | |
def OPS.[](cmd, *arg) | |
self.fetch([cmd, arg.first.class])[*arg] | |
end | |
Constant = Struct.new(:value) do | |
def initialize(v) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
ARGF.each do |line| | |
if /^\s*(\S+)\s+((?:\d{1,3}\.){3}\d{1,3})(?!\d)/ =~ line | |
host = $1 | |
listed_ip = $2 | |
begin | |
addrinfo = Socket::getaddrinfo(host, nil, :INET) | |
returned_ips = addrinfo.map {|a| a[3]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'benchmark' | |
require 'ostruct' | |
REP = 10**6 | |
Cl = Struct.new :name, :age | |
Benchmark.bmbm 20 do |x| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
FILE_NAME = "x" | |
printf "%-20s %p\n%-20s %p\n", | |
"Default external", Encoding.default_external, | |
"Default internal", Encoding.default_internal | |
# p File.instance_methods.grep(/enc|opt/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MichaelsLock | |
def initialize | |
@mx = Mutex.new | |
end | |
def lock_writer | |
@mx.synchronize do | |
raise "Already locked" if @writer | |
@writer = Thread.current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_xpath(node, xpath = "//") | |
xpath << node.name | |
first = true | |
node.attributes.values.each do |attr| | |
if first | |
first = false | |
xpath << "[" | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class X | |
def initialize | |
@l = lambda { return 123 } | |
@p = proc { return 456 } | |
@o = Proc.new { return 789 } | |
end | |
def l; @l.call end | |
def p; @p.call end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
class Logger | |
ENDL = "\n".freeze | |
def initialize(file_name) | |
@file_name = file_name | |
end | |
def log(message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
Group = Struct.new :name, :primary, :secondary, :editors | |
GET_UID = /uid=([^,]*)/ | |
EXTRACT = { | |
"dn" => [:name, /cn=([^,]*)/], | |
"owner" => [:primary, GET_UID], | |
"seeAlso" => [:secondary, GET_UID], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; |
NewerOlder