Skip to content

Instantly share code, notes, and snippets.

@dustMason
dustMason / knob.scad
Last active August 29, 2015 14:14
OpenSCAD Knobber Jobber Epcot Flavor
knob_radius = 24;
knob();
module knob() {
union() {
difference() {
sphere(r=knob_radius);
translate([0, 0, 0-(knob_radius)]) {
cylinder(r1=knob_radius, r2=knob_radius, h=knob_radius);
@dustMason
dustMason / gulpfile.js
Last active August 29, 2015 14:11
Gulp / Browserify
...
var makeScriptBundler = function(options) {
var cache = {};
// load the cache from disk
if (fs.existsSync(options.cache)) { cache = require(options.cache); }
var mainScriptPackageCache = {};
var bundler = browserify({
entries: options.entries,
extensions: ['.coffee'],
@dustMason
dustMason / Streamer.js
Created May 30, 2014 06:20
Streamer.js
var knox = require("knox");
var mpu = require("knox-mpu");
var s3lister = require("s3-lister");
var async = require("async");
var fs = require("fs");
var archiver = require("archiver");
var client = knox.createClient({
key: process.env.S3_ACCESS_KEY_ID,
secret: process.env.S3_SECRET_KEY,
@dustMason
dustMason / STDERR
Created May 30, 2014 00:17
s3 tar streamer attempt
events.js:72
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:133:12)
at WriteStream.Writable.write (_stream_writable.js:181:5)
at Pack.<anonymous> (/Users/jordan/Code/nuts.com/image-archiver/node_modules/knox-mpu/lib/multipartupload.js:246:28)
at Pack.EventEmitter.emit (events.js:95:17)
at EntryWriter.<anonymous> (/Users/jordan/Code/nuts.com/image-archiver/node_modules/tar/lib/pack.js:191:8)
at EntryWriter.EventEmitter.emit (events.js:95:17)
# I first implemented a solution in a naive style to feel out an algorithm.
# While sketching the first solution I realized that a version with much less
# complexity is easily written. The second version avoids exponential run-times
# by doing simple arithmetic on each iteration to avoid the call to
# Enumerable#reduce. I left both versions here so that you might get a feel for
# my thought process.
def pivot_index_v1 integers
pivot = -1
return pivot if integers.empty?
# Here is a sketch of some ActiveRecord models which could be used to support the features
# requested. I didn't code the implementation of the state machine as that isn't crucial
# to the question, but I think it would suit the system well and help in designing further
# features.
#
# The instance methods on the Seller model allow for flexibility of the rolling settlement
# window dates.
#
# As for indexing the tables, the most important one for the models below is:
# [:created_at, :seller_id] on the Transactions table. This makes the rolling settlement window
require 'open-uri'
require 'nokogiri'
base_uri = "http://www.thefremontproject.com"
path = "/rabbithole"
loop do
html = open(base_uri + path).read
link = Nokogiri::HTML(html).at_css("#next-link")
open("rabbithole.html", "wb") { |file| file.write(html) }
require 'net/http'
require 'json'
require 'uri'
uri = URI.parse "http://www.letsrevolutionizetesting.com/challenge.json"
loop do
response = JSON.parse(Net::HTTP.get_response(uri).body)
puts response
break unless response["follow"]
@dustMason
dustMason / application.rb
Last active December 18, 2015 17:19 — forked from t2/application.rb
Rails 3 ActionView override for Foundation 4 field error styles.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="error">#{html_tag})
html += %(<small>#{instance.error_message.to_a.to_sentence}</small>).html_safe unless html_tag =~ /^<label/
html += %(</div>)
html.html_safe
end
@dustMason
dustMason / threads.rb
Created May 31, 2013 03:38
Queue with finite number of threads pattern
@threads = []
@num_of_threads = 8
@queue = Queue.new
# fill queue with items ...
@num_of_threads.times do
@threads << Thread.new {
loop do
break if @queue.length == 0
do_something @queue.deq