Skip to content

Instantly share code, notes, and snippets.

@mikelikespie
mikelikespie / colors.js
Created October 22, 2010 23:01
Quick code to convert sRGB to CIE L*a*b* and back.
/*
* To try it:
* c = $c.sRGB8(23,58,32);
* c.Lab();
* c.Lab().sRGB8();
*/
var $c = {};
(
function () {
# robgleeson's fork much improved
class ErrorDelegate
attr_reader :pointer
alias_method :to_pointer, :pointer
def initialize
@pointer = Pointer.new_with_type '@'
end
@nkpart
nkpart / merge_sort.rb
Created October 14, 2011 04:04 — forked from kimhunter/merge_sort.rb
Merge sort ruby
#!/usr/bin/env ruby
# 2011-10-10 20:57:53 +1000
def merge_sort(a)
return a if a.size <= 1
l, r = split_array(a)
result = combine(merge_sort(l), merge_sort(r))
end
$graph = {a: [:b, :c], b: [:d, :e], c: [:f, :g]}
def dfs_nr(node)
queue = [node]
seen = {}
while not queue.empty?
node = queue.pop
puts node
seen[node] = true
if $graph[node]
@holman
holman / gemspec-usage.md
Created February 12, 2012 07:02
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'

@peterc
peterc / code2png.rb
Created February 19, 2012 00:32
code2png - Render code to an image on OS X
#!/usr/bin/env ruby
# code2png - Render code to an image on OS X
# Peter Cooper (@peterc)
# MIT license
#
# code2png converts source code into a PNG graphic
# (with syntax coloring, if you want). Ideal for
# Kindle document production, RSS feeds, etc.
#
@jboner
jboner / latency.txt
Last active November 19, 2024 14:58
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@matburt
matburt / i3plug.py
Created August 10, 2012 02:51
To be used with the i3 window manager (and i3-py). Takes a command 'save' or 'restore'. When 'save' is used it will store the monitor that each workspace is assigned to. When 'restore' is used it will restore those workspaces to the monitor that it was
import os
import i3
import sys
import pickle
def showHelp():
print(sys.argv[0] + " <save|restore>")
def get_visible_workspace():
for workspace in i3.get_workspaces():
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'motion-cocoapods'
require 'bundler'
Bundler.require
Dir.glob('lib/tasks/*.rake').each { |r| import r }
VERSION = "1.0.2"
@chiragchamoli
chiragchamoli / card.css
Created May 22, 2013 13:52
Google Card UI
body {
background: #f3f3f3;
}
.card {
background: url(http://i.imgur.com/wpb9BKE.jpg) center center white;
width: 350px;
height: 303px;
box-shadow: 0 1px 2px rgba(0,0,0,0.5);
border-radius: 3px 3px;
margin: 0 auto 10px;