Skip to content

Instantly share code, notes, and snippets.

View mattknox's full-sized avatar

matt knox mattknox

View GitHub Profile
@marcel
marcel / ConcurrentBlockingQueueConsumer.scala
Created March 24, 2011 22:43
Abstracts away the common pattern of producing items into a queue that are consumed concurrently by a pool of workers.
import java.util.concurrent.{BlockingQueue, ArrayBlockingQueue, CountDownLatch, Executors, TimeUnit}
/*
Abstracts away the common pattern of producing items into a queue that are
consumed concurrently by a pool of workers.
*/
class ConcurrentBlockingQueueConsumer[T](queue: BlockingQueue[T], producer: Iterator[T], concurrencyLevel: Int) {
lazy val stopLatch = new CountDownLatch(1)
lazy val pool = Executors.newFixedThreadPool(concurrencyLevel)
@ryanking
ryanking / gist:954555
Created May 4, 2011 00:55
Selectively stop classes from being modified in ruby.
# Ever get tired of people messing with your ruby classes?
# now you can put the hammer down and stop them. Just
# include this module and no one will be able to modify the
# class implementation or any instance implementations.
module Stop
module CantTouchThis
def self.included(mod)
@niallkennedy
niallkennedy / visibility.js
Created June 19, 2011 18:18
Page Visibility API visibility test using jQuery
var isVisible = false;
function onVisible() {
isVisible = true;
jQuery.getScript("http://www.google-analytics.com/ga.js");
}
if ( document.webkitVisibilityState === undefined || document.webkitVisibilityState === "visible" ) {
onVisible();
} else {
jQuery.bind( "webkitvisibilitychange", function() {
@erikeldridge
erikeldridge / oauth_util.rb
Created July 25, 2012 04:42
yet another OAuth util
require 'rubygems'
require 'oauth'
require 'awesome_print'
require 'uri'
# Usage:
# 1) Get consumer key/secret from https://dev.twitter.com/apps
# 2) Run ruby oauth_util.rb https://api.twitter.com/statuses/home_timeline.json
# 3) Authorize as instructed
# 4) $$$
#!/bin/bash
LAYOUT=sfdp
SIZE=300
echo `date`: Producing graph
cat mutual_uoi_follows | perl -ne 's/(\w+)\t(\w+)/"\1"\t->\t"\2"/ and print' | samp 1 | graphify > graph.gv
echo `date`: Splitting out largest connected component
cat graph.gv | ccomps -zX#0 > graph-cc0.gv
@dxnn
dxnn / conf-dates.txt
Last active June 20, 2016 23:30
Conferences worth proposing to
Ping me if you know of an awesome conference that isn't on this list.
Most of these cover the cost of conference, travel and lodging.
Dates are currently almost all for 2015.
JSConf US CFP: Jan 30 Conf: May 27-29 FL http://jsconf.us
Clojure/West CFP: Feb 11 Conf: Apr 20-22 PDX http://clojurewest.org
LambdaConf CFP: Feb 27 Conf: May 22 BLDR http://www.degoesconsulting.com/lambdaconf-2015/
SIGBOVIK CFP: Mar 15 Conf: Apr 1 CMU http://sigbovik.org
PolyConf CFP: Mar 28 Conf: Jul 2-4 Poland http://polyconf.com
Curry-On CFP: Apr 3 Conf: Jul 6-7 Prague http://www.curry-on.org
@Youka
Youka / ruby_interpreter.lua
Created December 30, 2014 11:25
Execute & bind Ruby by LuaJIT
-- Load foreign functions interface
local ffi = require("ffi")
-- Load Ruby library & define function headers
local ruby = ffi.load("msvcrt-ruby210")
ffi.cdef([[
typedef uintptr_t RUBY_VALUE;
enum{
RUBY_Qfalse = 0,
RUBY_Qtrue = 2,
@aphyr
aphyr / structure.clj
Created April 16, 2017 21:12
Extract a schema from a clojure object
(require '[clojure.walk :as w])
(defmacro both [a b pred] `(and (~pred ~a) (~pred ~b)))
(defn union-structure [a b]
(cond (= a b) a
(both a b vector?) [(reduce union-structure (concat a b))]
(both a b map?) (merge-with union-structure a b)
; Dunno, said the ghoul
@ryanking
ryanking / cantTouchThis.rb
Created December 6, 2013 01:03
I just stumbled on this bit of ruby code from a long time ago. Matt Knox and I were trying to solve the question of "can you selectively prevent monkey-patching in ruby?" I think this is the best we could do at the time.
# Ever get tired of people messing with your ruby classes?
# now you can put the hammer down and stop them. Just
# include this module and no one will be able to modify the
# class implementation or any instance implementations.
module Stop
module CantTouchThis
def self.included(mod)
Candidates for next platforms after PCs, phones, and tablets:
Virtual reality
Internet of things
Wearable computers
Cryptocurrencies / blockchain
Self-driving cars
Drones
Brain-computer interfaces
3d printing
Augmented reality