Skip to content

Instantly share code, notes, and snippets.

@cmsd2
cmsd2 / gist:995079
Created May 27, 2011 11:33
document.write replacement for jQuery
/*
---
source: http://gist.github.com/995079
based on script for MooTools: http://gist.github.com/133677
provides: document.write
description: jQuery based document.write replacement
requires: jQuery
author: Chris Dawes -- [email protected]
@cmsd2
cmsd2 / Revision.rb
Created June 17, 2011 09:09
Revision comparison using y combinator
#!/usr/bin/ruby -w
# Revision class
# Designed to function in version comparisons, where the
# version number matches /\d+(\.\d+)*/
# Author: Chris Dawes, Aupeo GmbH <[email protected]>
# Based on original by: Hugh Sasse, De Montfort University <[email protected]>
# And using: http://weblog.raganwald.com/2007/02/guest-blogger-tom-moertel-derives-y.html
def y(&f)
@cmsd2
cmsd2 / cache_stampede_prevention.rb
Created June 25, 2012 15:18
preventing cache stampede / dogpiling on rails
class FixedWindowCacheRefreshPolicy
def initialize(window)
@window = window
end
def nearly_expired?(cache_entry)
now = Time.now
expires_at = cache_entry.expires_at
if expires_at and (now + @window) > expires_at
@cmsd2
cmsd2 / gist:3858204
Created October 9, 2012 11:40
async and message passing channels for ruby
require 'thread'
class Counter
def initialize(start = nil)
@next = start || 0
@mutex = Mutex.new
end
def next
n = nil
@cmsd2
cmsd2 / ServerHbs.js
Created November 14, 2012 15:30
Server-side handlebar template compilation in a requirejs plugin
define(["text","hbs"], function(text,hbs) {
"use strict";
var buildMap = {};
var module = {
load: function(name, parentRequire, load, config) {
parentRequire(["hbs!" + name], function(hbsTemplate) {
var rawText = hbsTemplate({});
buildMap[name] = rawText;
@cmsd2
cmsd2 / r.js-eval-at-compile-time.patch
Created November 14, 2012 15:32
Modify r.js to evaluate at compile time functions loaded by plugins.
diff --git a/node_modules/requirejs/bin/r.js b/node_modules/requirejs/bin/r.js
index f2b8faa..9451e32 100644
--- a/node_modules/requirejs/bin/r.js
+++ b/node_modules/requirejs/bin/r.js
@@ -1065,7 +1065,9 @@ var requirejs, require, define;
}
load = bind(this, function (value) {
- this.init([], function () { return value; }, null, {
+ var factory = function () { return value; };
(gdb) bt
#0 0x00007f14bd7768f0 in oom::h8cb42d0549966493atb ()
#1 0x00007f14bd65ba6c in zookeeper::raw_vec::RawVec<T>::with_capacity (cap=18446744073709551615) at ../src/liballoc/raw_vec.rs:95
#2 0x00007f14bd65b9b0 in zookeeper::vec::Vec<T>::with_capacity (capacity=18446744073709551615) at ../src/libcollections/vec.rs:207
#3 0x00007f14bd65fc90 in zookeeper::vec::from_elem<u8> (elem=0 '\000', n=18446744073709551615) at ../src/libcollections/vec.rs:991
#4 0x00007f14bd68de03 in zookeeper::proto::R.BufferReader::read_buffer (self=0x7f14b9ffcc68) at src/proto.rs:62
#5 0x00007f14bd69af58 in zookeeper::proto::GetDataResponse.ReadFrom::read_from<std::io::cursor::Cursor<collections::vec::Vec<u8>>> (
reader=0x7f14b9ffcc68) at src/proto.rs:399
#6 0x00007f14bd699d11 in zookeeper::zookeeper::ZooKeeper::request<zookeeper::proto::StringAndBoolRequest,zookeeper::proto::GetDataResponse>
(self=0x7f14ba026100, opcode=GetData, xid=18, req=..., watch=...) at src/zookeeper.rs:118
@cmsd2
cmsd2 / crash-log.txt
Last active September 11, 2015 18:33
TRACE:mio::poll: registering with poller
TRACE:mio::poll: registering with poller
TRACE:mio::event_loop: event loop tick
INFO:zookeeper::io: Connecting to new server V4(172.x.x.x:2181)
INFO:zookeeper::io: Connected to V4(172.x.x.x:2181)
TRACE:mio::poll: registering with poller
TRACE:mio::event_loop: event loop tick
TRACE:zookeeper::io: notify Auth
TRACE:mio::timer: tick_to; now=0; tick=0
TRACE:mio::timer: ticking; curr=Token(18446744073709551615)

Keybase proof

I hereby claim:

  • I am cmsd2 on github.
  • I am cmsd2 (https://keybase.io/cmsd2) on keybase.
  • I have a public key ASDlWetzKwoqKXC5wYJMjoCO3xpLh2zfpoFkn4Vc4GZVjgo

To claim this, I am signing this object:

@-moz-document url-prefix(https://www.reddit.com/r/rust/) {
code {
color: white!important;
background-color: black!important;
}
/************************* BEGIN POST TEXT */
div.comment form p:last-of-type:after {
font-style: italic;