Skip to content

Instantly share code, notes, and snippets.

View heftig's full-sized avatar
🦄
Horsing around

Jan Alexander Steffens heftig

🦄
Horsing around
View GitHub Profile
# Need to block
begin
json = Timeout.timeout 3 do
Net::HTTP.new(uri.host, uri.port).start do |https|
https.request_get(uri.request_uri)
end
end
rescue Timeout::Error
if @retries >= 3
return {return: 'Gateway Timeout.', response: 504}
@heftig
heftig / gist:1164406
Created August 23, 2011 05:24 — forked from dmonopoly/gist:1164395
nil and false notion...
def mealtimes(meal)
arr = []
arr << "breakfast" if meal.breakfast
arr << "lunch" if meal.lunch
arr << "dinner" if meal.dinner
arr.join(", ").sub(/(.*),/, "\\1 and")
end
# Returns a hash of methods organized by their owner and method type.
module Kernel
def methods
output = {}
syms = [:public_methods, :protected_methods, :private_methods]
syms.each do |sym|
output[sym] = {}
send(sym).each do |m|
key = self.method(m).owner
#!/usr/bin/env ruby
require "librevox"
require "sequel"
DB = Sequel.connect('postgres://postgres:leenuhks@localhost/freeswitch')
class Outbound < Librevox::Listener::Outbound
def session_initiated
answer
# Always wanted to chain comparisons the snaky way?
#
# puts 'Right there!' if 5 < x <= 15
#
# There you go.
class FalseClass
['<', '>', '<=', '>='].each do |op|
eval "def #{op}(other) false end"
end