Skip to content

Instantly share code, notes, and snippets.

@egonSchiele
egonSchiele / canny.cpp
Created December 28, 2010 02:42
Adding automatic thresholding to cvCanny in OpenCV
// new
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
@egonSchiele
egonSchiele / hfsslower.d
Created March 10, 2012 19:20
copy of Brenden Gregg's hfsslower.d
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option defaultargs
#pragma D option switchrate=10hz
/* from http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/ */
dtrace:::BEGIN
{
@egonSchiele
egonSchiele / soconnect.d
Created March 10, 2012 20:23
Brendan Gregg's soconnect.d script
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option switchrate=10hz
inline int af_inet = 2; /* AF_INET defined in bsd/sys/socket.h */
inline int af_inet6 = 30; /* AF_INET6 defined in bsd/sys/socket.h */
/* from http://dtracebook.com/index.php/Network_Lower_Level_Protocols:soconnect.d#Mac_OS_X */
@egonSchiele
egonSchiele / install_homebrew.rb
Created July 2, 2012 06:41
less annoying install_homebrew.rb
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/egonSchiele/homebrew/tarball/master anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
@egonSchiele
egonSchiele / chk.rb
Created July 7, 2012 04:21
Find undefined symbols in a ruby script
require 'rubygems'
require 'ruby2ruby'
require 'ruby_parser'
require 'set'
require 'trollop'
require 'contracts'
include Contracts
class Foo < SexpProcessor
@egonSchiele
egonSchiele / bench.rb
Last active November 11, 2017 10:09
Benchmarking OpenStruct alternatives
require 'benchmark'
require 'ostruct'
require 'rubygems'
require 'deep_struct'
require 'classy_struct'
require 'structure'
require 'deepopenstruct'
require 'recursive-open-struct'
require './fast_struct/lib/fast_struct'
@egonSchiele
egonSchiele / wrap_bench.rb
Created March 4, 2013 23:17
Time difference between wrapped methods and regular methods
require 'benchmark'
module Wrapper
def self.extended(klass)
klass.class_eval do
@@methods = {}
def self.methods
@@methods
end
def self.set_method k, v
@egonSchiele
egonSchiele / Main.hs
Created April 17, 2013 00:03
Read and write from a database using persistent and Scotty
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
@egonSchiele
egonSchiele / rons.rb
Last active October 30, 2022 06:16
The dining philosophers problem in Ruby, solved using the resource hierarchy solution
require 'thread'
class Ron
def initialize(name, left_fork, right_fork)
@name = name
@left_fork = left_fork
@right_fork = right_fork
while true
think
dine
@egonSchiele
egonSchiele / dining01.rb
Created May 13, 2013 01:50
A celluloid implementation of dining philosophers where the forks are actors too. Could cause deadlock since we wait on forks.
require 'rubygems'
require 'celluloid'
class Philosopher
include Celluloid
def initialize(name, left_fork, right_fork)
@name = name
@left_fork = left_fork
@right_fork = right_fork
self.think