Skip to content

Instantly share code, notes, and snippets.

View rkh's full-sized avatar
👀
heeeyyyy

Konstantin Haase rkh

👀
heeeyyyy
View GitHub Profile
@rkh
rkh / compare_gems.sh
Created February 4, 2009 12:28
all your gems for ruby 1.9.1
#!/bin/bash
gem1.8 list --local --no-versions > 1.8.txt
gem1.9 list --local --no-versions > 1.9.txt
diff gem1.8.txt gem1.9.txt
@rkh
rkh / alg_earliestdeadlinefirst.c
Created February 4, 2009 18:36
primitive scheduler algorithms
#include "algorithms.h"
#include "dispatcher.h"
HANDLE Algorithm_EarliestDeadlineFirst(PLIST_ENTRY TaskList, ULONG Clock) {
PLIST_ENTRY ListEntry, Candidate;
HANDLE CandidateThreadHandle, ListEntryThreadHandle;
PDISPATCHER_TASK ListEntryTask;
PEDF_TASKINFO ListEntryTaskInfo, CandidateTaskInfo;
@rkh
rkh / repl
Created February 17, 2009 15:35
ruby -e "loop { print '>> '; puts('=> ' + eval(gets).inspect) }"
require "rubygems"
require "snmp"
mac = ARGV.shift.dup
unless mac.gsub! /^(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?$/, '\1 \2 \3 \4 \5 \6'
puts "illegal mac"
exit
end
mac = mac.split(" ").collect { |hex| eval("0x#{hex}").to_s }.join "."
@rkh
rkh / git-thanks
Created March 5, 2009 12:41 — forked from rares/git-thanks
#!/bin/sh
# Usage: git-thanks <since>..<until>
#
# All commits on master, ever:
# git-thanks master
#
# All commits on master since the 0.9.0 tag:
# git-thanks 0.9.0..master
git log "$1" |
require "socket"
require "drb"
uri = ARGV.shift
# Socket overwrites send!
class Wrapper
include DRb::DRbUndumped
def initialize object
@object = object
@rkh
rkh / irb
Created March 19, 2009 14:14
CRuby 1.8.7 >> Switch.first
CRuby 1.8.7 => #<Switch ip_address=#<IPAddr: IPv4:192.168.1.240/255.255.255.255> name=nil>
CRuby 1.8.7 >> Port.first
CRuby 1.8.7 => #<Port trunk=false port_number=1 switch_ip_address=#<IPAddr: IPv4:192.168.1.240/255.255.255.255>>
CRuby 1.8.7 >> Switch.first.ports
NoMethodError: undefined method `ports_association' for nil:NilClass
from /home/konstantin/.config/irb/myirb.rb:108:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.10/lib/dm-core/associations/relationship.rb:108:in `send'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.10/lib/dm-core/associations/relationship.rb:108:in `get_children'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.10/lib/dm-core/associations/relationship.rb:107:in `each'
module Enumerable
class Evaluator
instance_methods.each { |s| undef_method(s) unless s.to_s =~ /__/ }
def initialize(enum, invoke=nil, *args)
@enum = enum
@invoke = invoke
@args = args
end
require "parse_tree"
require "ruby2ruby"
module SexpStuff
def r2r(a, b = nil)
return Ruby2Ruby.new.process a if a.is_a? Sexp
r2r u(a, b = nil)
end
require "cheap_proc"
file = "/tmp/stored_proc"
unless File.exists? file
foo = 42
cheap = lambda { puts foo }.to_cheap_proc
File.open(file, "w") { |f| f.write(cheap.dump) }
else
cheap = File.read(file).to_cheap_proc
end