Skip to content

Instantly share code, notes, and snippets.

@havenwood
havenwood / cheating.rb
Created August 30, 2014 23:28
Klass Module
module Klass
def self.new *args, &block
object = Class.allocate
object.send :initialize, *args, &block
object
end
end
Cat = Klass.new do
attr_reader :name, :age
@matthewmueller
matthewmueller / osx-for-hackers.sh
Last active February 20, 2025 09:37
OSX for Hackers (Mavericks/Yosemite)
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@epitron
epitron / lugcast.js
Last active July 3, 2016 18:18
An audio player I wrote for the SteamLUG Podcast (https://steamlug.org/cast). It highlights the transcript as the audio is playing, and lets you jump around in the audio by clicking the transcript.
(function () {
"use strict";
function time_to_seconds(time) {
var s = time.attributes.datetime.value.split(":");
return parseInt(s[0] * 3600, 10) + parseInt(s[1] * 60, 10) + parseInt(s[2], 10);
}
var highlighter = {
@whylom
whylom / README.md
Created December 4, 2014 23:43
A parser for Heroku log messages

A parser for Heroku log messages

This parser uses the Parslet to define rules for parsing a log message in the simple key=value format used by Heroku, eg:

at=error code=H12 desc="Request timeout" method=GET path="/foo" dyno=web.3 connect=1ms service=30000ms status=503 bytes=0

Given a message in the above format, the parser returns a hash of the key/value pairs:

@u8sand
u8sand / QtUiCleaner
Created December 24, 2014 00:20
Sometimes Qt Creator doesn't clean up after itself--this should take care of that.
#!/bin/python3
import sys;
from lxml import etree;
def clean(f):
print("Processing "+f+"...")
tree = etree.parse(f)
root = tree.getroot()
used_actions=[]
anonymous
anonymous / idc.d.d
Created January 6, 2015 03:55
idc.d
module idc; // Internet delay chat! Yay!
import tools.fixed_socket, tools.base;
import tools.log, tools.threads, tools.threadpool;
import tools.time;
import readback;
string download(string url, bool first = false) {
if (url.find("://") == -1) url = "http://"~url;

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@havenwood
havenwood / matrix_fib.rb
Last active October 24, 2016 23:32
nth fib with Matrix exponentiation in Ruby
require 'matrix'
def fib n
matrix = Matrix[[0, 1], [1, 1]] ** n.pred
matrix[1, 1].to_i
end
require 'minitest/autorun'
require 'minitest/pride'
@havenwood
havenwood / proc_compose.rb
Last active August 29, 2015 14:14
Composing with Procs
class Proc
class << self
def compose *others
others.map(&:to_proc).inject :*
end
end
def * other
proc { |*args| other.call self.call *args }
end