Skip to content

Instantly share code, notes, and snippets.

View robotmay's full-sized avatar

Robert May robotmay

View GitHub Profile
@robotmay
robotmay / memory_usage.rb
Last active December 31, 2015 03:19
A Ruby utility script for use in `git bisect`. Returns a non-0 exit code if memory usage for the process exceeds a specified number.
# To run git bisect looking for the first spec suite to exceed 1000MB of RAM:
# git bisect run ruby memory_usage.rb 'rake spec' 1000000
require 'open3'
command = ARGV[0]
threshold = ARGV[1].to_i || 500000
cmd = "/usr/bin/time -v #{command}"
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
@robotmay
robotmay / dashing-heroku.md
Last active November 29, 2016 11:59
Heroku jobs for Dashing. Returns the number of active dynos for each process type (including custom processes). Set your Heroku keys as environment variables.

Add the following to your Gemfile:

gem 'heroku-api'

Put heroku.rb in your jobs folder and add the contents of heroku.html into your layout.

#Rails Girls Things

Rob's Introduction to Programming

@robotmay
robotmay / pusher.js.coffee
Last active December 12, 2015 12:28
An in progress, broken, Pusher adapter for Ember.js
Kuiper.Pusher = (opts = {}) ->
@init(opts)
this
$.extend Kuiper.Pusher.prototype,
options: {}
activeChannels: []
init: (@options) ->
@pusher = new Pusher(@options.key)
@robotmay
robotmay / model.js.coffee
Created February 12, 2013 11:45
Ignore the crappy Ajax bit!
DS.Model.reopenClass
modelName: ->
model = this
parts = model.toString().split('.')
name = parts[parts.length - 1]
name.replace(/([A-Z])/g, '_$1').toLowerCase().slice(1)
getChannelPrefix: (callback) ->
@channelPrefix || $.get "/accounts/current.json", (data) ->
@channelPrefix = data['account']['pusher_channel']
@robotmay
robotmay / app.rb
Created February 8, 2013 15:23
Example of how to hide flash messages
...
def create
flash[:alert] = "You created a thing!"
redirect_to "/somepath"
end
...
@robotmay
robotmay / checkboxes.coffee
Last active December 11, 2015 22:08
Rig checkboxes to look like links, because so many designers seem to want this lately. Adds a 'checked' class to the checkbox label and hides the input.
switchLabelClass = (el) ->
if $(el).attr("checked") == "checked"
$(el).parent().addClass("checked")
else
$(el).parent().removeClass("checked")
# Obviously change the form target here
checkbox_groups = $("form").find("input[type = 'checkbox']").each ->
$(this).hide()
switchLabelClass(this)
@robotmay
robotmay / client.rb
Created January 29, 2013 15:19
Playing around with Rust and ZMQ
require "celluloid/zmq"
Celluloid::ZMQ.init
class Client
include Celluloid::ZMQ
def initialize(address)
@socket = PushSocket.new
@robotmay
robotmay / brutix.go
Created August 29, 2012 12:32
Simple (and largely pointless) hash generator in Go
// Wrote this to try bruteforcing a hash key in part of the Stripe CTF game.
// I realise it would take something like 100 million years to find it, but I'd never written a hash generator before.
// Putting this on GitHub in case anyone's interested.
package main
import (
"math/rand"
"strings"
"bytes"
@robotmay
robotmay / place.rb
Created July 11, 2012 11:50
Scaling down
def ddg_info
@ddg_info ||= Rails.cache.fetch("places/#{id}-#{updated_at}/ddg_info", expires_in: 3.days) do
data = DDG.zeroClickInfo(name)
end
end