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() {
@JoshuaEstes
JoshuaEstes / 000-Cheat-Sheets.md
Last active May 1, 2024 04:03
Developer Cheat Sheets for bash, git, gpg, irssi, mutt, tmux, and vim. See my dotfiles repository for extra info.
@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
@PaulKinlan
PaulKinlan / criticalcss-bookmarklet-devtool-snippet.js
Last active October 12, 2024 16:34
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@abeppu
abeppu / feelbetter.js
Last active February 6, 2021 19:06
Implementation of @FeelBetterBot
var Twit = require("twit");
var config = require('./oauthconfig');
console.log("config:");
console.log(config);
var T = new Twit({
consumer_key: config.consumer_key,
consumer_secret: config.consumer_secret,
access_token: config.access_token,
@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)
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active September 12, 2024 16:16
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.