Skip to content

Instantly share code, notes, and snippets.

@havenwood
havenwood / hello.cr
Created April 17, 2015 00:09
"Hello, world!" from MRuby embedded in Crystal
@[Link("mruby")]
lib MRuby
type MRubyState = Void*
fun open = mrb_open : MRubyState
fun load_string = mrb_load_string(mrb : MRubyState, code : Pointer(UInt8))
fun close = mrb_close(mrb : MRubyState)
end
CODE = <<-RUBY_CODE
@paulirish
paulirish / bling.js
Last active May 2, 2026 11:52
bling dot js
/* bling.js */
window.$ = document.querySelector.bind(document);
window.$$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); };
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); };
@imjasonh
imjasonh / markdown.css
Last active September 3, 2025 22:12
Render Markdown as unrendered Markdown (see http://jsbin.com/huwosomawo)
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@havenwood
havenwood / roshambo.rb
Created February 10, 2015 18:04
Example of Comparable with Roshambo
class Roshambo
OPTIONS = [:rock, :paper, :scissors]
WINNERS = OPTIONS.rotate.zip(OPTIONS).to_h
LOSERS = WINNERS.invert
attr_reader :value
include Comparable
def initialize value = OPTIONS.sample
@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
@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'

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).

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;
@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=[]