Skip to content

Instantly share code, notes, and snippets.

View kylev's full-sized avatar
💭
Pushing the (mostly) right buttons.

Kyle VanderBeek kylev

💭
Pushing the (mostly) right buttons.
View GitHub Profile
02:53 <@kylev> anyone awake?
02:55 <@emopants> no
02:55 <@kylev> can you reach www.change.org?
02:56 <@emopants> no
02:56 <@emopants> 10 AMAZON.COM.edge2.Washington1.Level3.net (4.79.22.2) 95.528 ms
AMAZONCOM.edge2.Washington1.Level3.net (4.79.22.10) 96.821 ms
AMAZONCOM.edge2.Washington1.Level3.net (4.79.230.46) 96.502 ms
02:56 <@emopants> 11 * * *
02:57 <@emopants> looks like the amazon cloud is angry
02:57 <@emopants> 8 vadata-gw.ip4.tinet.net (173.241.128.46) 114.560 ms 112.409 ms
@kylev
kylev / gist:1050398
Created June 28, 2011 03:03
Attempt to prevent errors from subdomain-fu on 2.3.8 when people request/probe using an IP-based URL
diff --git a/lib/core_extensions/action_controller_request.rb b/lib/core_extensions/action_controller_request.rb
index fcd578c..08bdd4a 100644
--- a/lib/core_extensions/action_controller_request.rb
+++ b/lib/core_extensions/action_controller_request.rb
@@ -7,4 +7,11 @@ class ActionController::Request
end
end
+
+ BASE_CHANGE_DOMAIN = ENV['BASE_URL'].split(':')[0]
@kylev
kylev / dev.rake
Created September 22, 2011 22:34
Simple rake example for generating the configs a new developer will need to start up their environment.
DATABASE_YAML = <<-YML
defaults: &defaults
adapter: mysql2
username: root
password:
host: localhost
port: 3306
development:
<<: *defaults
timed_loop_batch(0.25, 1000, 100) do |batch_size|
changed = GiantMetric.connection.update_sql("DELETE FROM giant_metrics WHERE created_at <= #{1.month.ago} LIMIT #{batch_size}")
break if changed < batch_size
end
module Capybara
class Session
# `execute_script` variant that first waits for jQuery's $ to be defined.
def execute_jquery(script)
synchronize_javascript("$ !== 'undefined'")
execute_script(script)
end
# `evaluate_script` variant that first waits for jQuery's $ to be defined.
class Object
def wtf!
raise (self.respond_to?(:pretty_inspect) ? self.pretty_inspect : self.inspect)
end
end
@kylev
kylev / foggy.rb
Last active December 17, 2015 08:29
Examples for streaming data to/from S3 via Fog.
# Create happily takes IO-like objects as body.
file = directory.files.create(
:key => 'giant_linux_distro.iso',
:body => File.open("nightly.iso"), # No ma! No read()!
:public => true
)
# Get will take a block for streamy goodness.
directory.files.get("giant_thing.bin") do |chunk, remaining, total|
output.write(chunk)
@kylev
kylev / signals_badly.rb
Last active August 29, 2015 14:26
An exploration of common pitfalls in Ruby Exception/Signal handling.
#!/usr/bin/env ruby
# Some members of ruby community continue to misunderstand the interplay of
# signal handlers and exception handling. This is a brief exploration
# via examples. You can run them by uncommenting the invocations at
# the bottom. You can see their behavior with Ctrl-C.
#
# Some of the examples will require a kill -9 from another terminal to
# stop.
#
@kylev
kylev / hoistedFunc.js
Last active September 15, 2015 04:37
function noBar() {
console.log(bar());
}
// ReferenceError: bar is not defined
function hoistedVar() {
console.log(bar());
var bar = function() {
return 42;
@kylev
kylev / MIDI_Visual_Metronome.ino
Last active October 29, 2020 15:38
This is the code for an Arduino MIDI "visual metronome". I wrote it using a Sunfounder Uno R3 and a Sparkfun MIDI shield (with only the MIDI In connector installed).
/**
* MIDI Visual Metronome
*
* Developed on Sparkfun Uno R3 and Sparkfun MIDI Shield.
*
* Reqires the popular FortySevenEffects MIDI library:
* https://github.com/FortySevenEffects/arduino_midi_library
*
* The intended application is with MIDI and electronic music in
* a situation where proper stage or in-ear monitors are not