Skip to content

Instantly share code, notes, and snippets.

@rehanift
rehanift / *scratch*
Created October 5, 2011 05:01
this is my test
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
Hello World!
@rehanift
rehanift / init.el
Created October 12, 2011 17:08
How to get js2-additional-externs working with js2-mode
(defun rli-add-jasmine-externs()
(when (string-match "_spec.js" (buffer-file-name))
(setq js2-additional-externs
'("jasmine" "describe" "xdescribe" "it" "xit" "expect" "spyOn"
"beforeEach" "afterEach" "runs" "waits" "waitsFor")))
)
(add-hook 'js2-mode-hook 'rli-add-jasmine-externs)
@rehanift
rehanift / locals-demo.js
Created October 30, 2011 20:52
engine.js locals demo
var engine = require("./engine").engine;
var client, task, intake, exhaust, cylinder, logging_gateway, stdout_client, logging_opts;
logging_gateway = engine.logging_gateway.create();
stdout_client = engine.logging_stdout_client.create();
logging_gateway.add_logger(stdout_client);
logging_opts = {
logging_gateway: logging_gateway
};
@rehanift
rehanift / fetch-demo.js
Created October 30, 2011 20:53
engine.js fetch context
var fetch = function(resource, options, callback){
var url = require("url");
var http = require("http");
var parsed_url = url.parse(resource);
var http_options = {
host: parsed_url.hostname,
port: parsed_url.port || 80,
path: parsed_url.pathname + (parsed_url.search || "") + (parsed_url.hash || ""),
method: options.method || "GET"

this is some code

@rehanift
rehanift / *scratch*
Created November 24, 2011 21:43
Integrating 0mq w/ EventMachine into a rails application
* Rack
- Rack::FiberPool provides a Fiber for each request
* Application Server
- Thin: starts its own EM reactor
- Passenger: Start a new reactor in a new thread
- Other: Start a new reactor in a new thread
* Rails
- initialzier: Start a new EM reactor (depending on app server)
@rehanift
rehanift / *scratch*
Created December 2, 2011 05:05
Testable Code
* Don't mock interfaces that you do not own
* Do not do real work in the constructor
* Respect the law of demeter
* Tell dont ask
* Use concrete mock objects
@rehanift
rehanift / vm-events.js
Created December 10, 2011 17:12
Node VM waiting for event listeners to fire
var vm = require("vm"),
util = require("util"),
events = require("events");
var fooClass = function(){};
util.inherits(fooClass, events.EventEmitter);
fooClass.prototype.run = function(){
this.emit('myevent', "Hello!");
};
@rehanift
rehanift / .emacs
Created December 18, 2011 06:14
dot-emacs
(if (< emacs-major-version 24)
(load "~/.emacs_23")
(load "~/.emacs24.d/init.el"))
@rehanift
rehanift / acme_service_client.rb
Created February 15, 2012 14:43
Decoupled dependency injection
class AcmeServiceClient
def initialize(http_client, acme_response_translator)
self.http_client = http_client
self.acme_response_translator = acme_response_translator
end
def self.make(dependencies)
instance = self.new(dependencies["http_client"], dependencies["acme_response_translator"])
return instance
end