Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am carlthuringer on github.
  • I am carlthuringer (https://keybase.io/carlthuringer) on keybase.
  • I have a public key ASChpeUaIF3y0bdYpCx4H24Yh3gFyu63erD7cpwPwOkKwwo

To claim this, I am signing this object:

@carlthuringer
carlthuringer / exceptions.rb
Created November 29, 2017 15:31
Ruby Snippet for printing all exception heirarchy
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
end
@carlthuringer
carlthuringer / forth.rb
Created August 4, 2017 11:40 — forked from fogus/forth.rb
Forth interpreter in 64 lines of Ruby
#!/usr/bin/env ruby
def pop; $stack.pop || raise(StackUnderflow); end
def push(expression); $stack << expression; end
def unary; -> { push(yield pop) }; end
def binary; -> { push(yield pop, pop) }; end
def unary_boolean; -> { push(if yield pop then 1 else 0 end) }; end
def binary_boolean; -> { push(if yield pop, pop then 1 else 0 end) }; end
def swap; $stack[-2,2] = $stack[-2,2].reverse; end
$stack = []
@carlthuringer
carlthuringer / bmi.php
Last active September 19, 2016 15:15
BMI
<?php
/*
* calc_bmi
* The structure of this function is misleading and overcomplicated.
* The function returns false or a value, so any program calling it must handle
* either false or a value.
* Further, the function is burdened with mistrust and has misleading default arguments.
* The default arguments suggest that the function expects integers, but it actually handles strings and many other possible values.
*/
@carlthuringer
carlthuringer / integratioN_test.rb
Created May 27, 2016 15:52
Supposed to create a workflow in backbeat
it "runs a workflow from java to ruby, back to java" do
# Because our Backbeat client is set up with the ruby credentials, we cannot use it to prove this test's functionality.
# Instead, we have to craft the requests by hand.
backbeat_host = URI("http://#{ENV['BACKBEAT_SERVER_HOST']}:#{ENV['BACKBEAT_SERVER_PORT']}")
# Create the workflow
create_workflow_request = Net::HTTP::Post.new(URI.join(backbeat_host, "/workflows"))
set_client_headers(create_workflow_request, :java)
class CalculatesTax
include LightService::Organizer
def self.for_order(order)
with(:order => order).reduce(
[FetchesTaxRangesAction, FetchesCachedTaxRangesAction],
LooksUpTaxPercentageAction,
CalculatesOrderTaxAction,
ProvidesFreeShippingAction
fallback: GenericErrorHandler
@carlthuringer
carlthuringer / tmux.md
Last active August 29, 2015 14:09 — forked from andreyvit/tmux.md

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Sessions, windows, panes

Session is a set of windows, plus a notion of which window is current.

Window is a single screen covered with panes. (Once might compare it to a ‘virtual desktop’ or a ‘space’.)

@carlthuringer
carlthuringer / gist:11230097
Created April 23, 2014 19:56
Composition or Decoration?
class Decorator
def self.decorate(subject)
subject.define_singleton_method(:with) do |delegate|
@delegate_list ||= []
@delegate_list << delegate
end
subject.define_singleton_method(:method_missing) do |meth, *args, &block|
begin
@delegate_list.find do |delegate|
@carlthuringer
carlthuringer / gist:8788196
Created February 3, 2014 17:24
Ethon Segfault OS X Mavericks
/Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ethon-0.6.2/lib/ethon/easy/operations.rb:23: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin13.0.2]
-- Control frame information -----------------------------------------------
c:0098 p:---- s:0507 b:0507 l:000506 d:000506 CFUNC :easy_perform
c:0097 p:0024 s:0503 b:0503 l:000502 d:000502 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ethon-0.6.2/lib/ethon/easy/operations.rb:23
c:0096 p:0036 s:0500 b:0500 l:000499 d:000499 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/request/operations.rb:16
c:0095 p:0074 s:0496 b:0496 l:000495 d:000495 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/request/cacheable.rb:18
c:0094 p:0050 s:0492 b:0492 l:000491 d:000491 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/requ
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end