Skip to content

Instantly share code, notes, and snippets.

View bobbytables's full-sized avatar
🔥
Putting out fires

Robert Ross bobbytables

🔥
Putting out fires
View GitHub Profile
@brianstorti
brianstorti / priority_queue.rb
Last active November 17, 2022 16:14
Priority queue implementation in Ruby
class PriorityQueue
attr_reader :elements
def initialize
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
@jandudulski
jandudulski / auth.rb
Last active September 14, 2022 12:09
CSRF on Grape
# based on http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
module Auth
extend ActiveSupport::Concern
included do
helpers do
def session
env['rack.session']
end
(Chapters marked with * are already written. This gets reorganized constantly
and 10 or so written chapters that I'm on the fence about aren't listed.)
Programmer Epistemology
* Dispersed Cost vs. Reduced Cost
* Verificationist Fallacy
* Mistake Metastasis
The Overton Window
Epicycles All The Way Down
The Hyperspace Gates Were Just There
require "timeout"
module WaitSteps
extend RSpec::Matchers::DSL
matcher :become_true do
match do |block|
begin
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = block.call
@jimarnold
jimarnold / adventures_in_go.md
Created November 5, 2012 22:35
Adventures in Go

Executive summary

Go is C with type-safety and garbage collection, and Java without all the Java. It does a fairly good job of getting out of your way, but it is, to me, a language of compromises. It is strongly, statically typed but lacks generics. It has useful built-in types but they act very differently to the types you can create for yourself. It wants to be a modern language but uses 40 year old syntax. The core library is a confusing mix of functions-that-act-on-values and methods-on-types.

That said, I have enjoyed using it. It's compiled, but there is very little compiler wrangling due to the way your source files must be structured, and external dependencies are resolved from source, not from linker arguments. It's fast. It feels familiar. The concurrency and functional aspects are great. Would I recommend it to a client? Not yet - Java and C# are far more mature and Go doesn't offer anything compelling for the types of programs you might use those languages for (it has been said of Go that it

@zefer
zefer / copy-s3-bucket.rb
Created April 4, 2011 11:24
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
aws_access_key_id = 'your-access-key'
aws_secret_access_key = 'your-secret-key'
target_bucket = 'your-source-bucket'
destination_bucket = 'your-destination-bucket'
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)