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
@kylev
kylev / Dockerfile
Last active September 21, 2022 00:43
A complete Alpine docker-compose Rails workflow with PostgreSQL and Redis
FROM ruby:2.6-alpine
# Additional runtime facilities provided by the OS.
RUN apk add --no-cache libxml2 libxslt postgresql-libs tzdata
# Tell bundler how to use the OS.
RUN gem install bundler -v '~> 1.17' && \
bundle config build.nokogiri --use-system-libraries
WORKDIR /opt/app
RUN mkdir -p tmp/pids tmp/cache
@kylev
kylev / maryhad.clj
Last active December 7, 2017 02:46
"Mary Had a Little Lamb" in Clojure
(ns tutorial.maryhad
"Implementation of \"Mary Had a Little Lamb\"
Found here:
http://www.pianolessons4children.com/sheetmusic/Mary_Had_a_Little_Lamb_C_Major.pdf"
(:require [leipzig.live :as live]
[leipzig.melody :refer :all]
[leipzig.scale :as scale]
[overtone.inst.piano :refer [piano]]
[overtone.live :refer :all]))
@kylev
kylev / bson2json.rb
Last active November 25, 2016 04:45
Using an eigenclass to make some instances of BSON::ObjectId to serialize to JSON as strings.
require 'json'
require 'bson'
a = BSON::ObjectId.new
b = BSON::ObjectId.new
puts a.to_json
# {"$oid":"5837b91f775ab9717f8d8bc9"}
puts b.to_json
# {"$oid":"5837b92c775ab9717f8d8bca"}
@kylev
kylev / aws-op-list.rb
Last active March 17, 2021 02:51
A script to print all the operations in each AWS service endpoint. Useful for crafting well-formed IAM permissions.
#!/usr/bin/env ruby
# List all the (known) operations on each AWS service API. This is
# incredibly useful for building well-restricted IAM access
# rules. With this list you can quickly see what "s3:Get*" matches, or
# just glance through and look for something that might be missing and
# breaking your app.
# I can't believe I had to write this myself. I'm pretty sure there
# are a lot of people out there with near-god-mode permission on IAM
@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
@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 / 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 / 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)
class Object
def wtf!
raise (self.respond_to?(:pretty_inspect) ? self.pretty_inspect : self.inspect)
end
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.