Skip to content

Instantly share code, notes, and snippets.

View rbishop's full-sized avatar

Richard Bishop rbishop

View GitHub Profile
@rbishop
rbishop / rainforest.rb
Created June 10, 2014 20:41
rainforest
require 'httparty'
fetch = -> (url) {
HTTParty.get(url, headers: { "Accept" => "application/json"})
}
response = fetch.("http://letsrevolutionizetesting.com/challenge.json")
begin
next_url = response["follow"]
@rbishop
rbishop / gist:10986218
Created April 17, 2014 14:07
OpenSSH iptables for Arch
iptables -A OUTPUT -t mangle -p tcp --dport 22 -j TOS --set-tos 0x00
@rbishop
rbishop / carl_hewitt_actor_model.md
Last active April 3, 2024 06:58
Notes from Carl Hewitt on the Actor Model

Carl Hewitt on Actors

Actor - Fundamental unit of computation, a computation model - not just a form of concurrency

An Actor has three essential elements:

  • 1 - Processing - you have to get something done
  • 2 - Storage - you have to be able to remember things
  • 3 - Communication
@rbishop
rbishop / decorator_perf.rb
Created November 20, 2013 00:40
Disclaimer: Yes, this is performance testing and Ruby. Obviously we choose Ruby for it's other greater qualities. Playing around with performance regarding the various ways you can implement Decorators in Ruby.
require 'benchmark'
require 'delegate'
require 'forwardable'
class Person
def initialize(name)
@name = name
end
def name
@rbishop
rbishop / concern.rb
Created October 3, 2013 23:54
I imagine this is due to how ActiveSupport::Concern handles dependency resolution? It's pretty surprising though because you can use most other Rails class methods (before_filter, helper_method, belongs_to, etc. etc.) in the included method's block.
module Surprisable
extend ActiveSupport::Concern
included do
attr_accessor :this_aint_gonna_work
end
end
module Wtfable
extend ActiveSupport::Concern
@rbishop
rbishop / gist:4974678
Created February 18, 2013 01:56
Fixes the issue where the fixed navigation menu in Twitter Bootstrap sits on top of your main div container.
// Add #main to the second div.container
@media (min-width: 720px) {
#main {
margin-top: 50px;
}
}
Rails.cache.fetch :group_id => group.id, :goal_id => self.id do
Post.find_by_sql(
"#{Post.where(:attachment_type => 'UserGoalLog').where(Post.arel_table[:attachment_id].in(user_goal_logs.collect(&:id))).to_sql}
UNION
#{Post.where(:attachment_type => 'UserGoal').where(Post.arel_table[:attachment_id].in(user_goals.collect(&:id))).to_sql}"
)
end
@rbishop
rbishop / largest_prime_factor.rb
Created February 10, 2013 21:49
Euler problem #3
def largest_prime_factor num
factor = 2
product = 1
while product != num
factor += 1
if num % factor == 0
product *= factor
end
end
return factor
@rbishop
rbishop / object_send.js
Created January 24, 2013 04:59
So, everything is an object eh, JavaScript? Then every object should have a send method! This is just for fun of course and I pray to not be punished by the gods for extending native prototypes. How fun is it to have a ton of dynamic method dispatching at your hands though?
Object.prototype.send = function(methodName) {
args = [].slice.call(arguments);
args.shift()
if (this.hasOwnProperty(methodName)) return this[methodName];
if (args.length > 1) {
return this[methodName].apply(this, args);
} else {
return this[methodName]();
@rbishop
rbishop / repl.rb
Last active March 23, 2016 11:32
Minimal implementation of a REPL in Ruby. WAT?!
while true
line_num ||= 1
("%03d" % line_num + ' > ').display
code = gets
puts eval(code)
line_num += 1
end