Skip to content

Instantly share code, notes, and snippets.

@jagoda
jagoda / terminal.css
Created November 28, 2011 19:46
jQuery UI Terminal Widget
.terminal-cursor {
background-color: #00ff00;
color: black;
}
.terminal-console {
background-color: black;
font-family: monospace, courier, arial;
color: #00ff00;
@jagoda
jagoda / fixed_stream.js
Created December 23, 2011 16:42
NodeJS wrapper to treat strings as streams.
var events = require('events');
var util = require('util');
function FixedStream (string) {
events.EventEmitter.call(this);
this._buffer = new Buffer(string);
this._data = [];
this._end = false;
}
@jagoda
jagoda / doh.py
Created April 6, 2012 18:09
django.test + DOH
# Unit testing support for DOH.
from django.conf import settings
from django.test import TestCase
import os
import subprocess
from time import sleep
from urlparse import parse_qs as parse
@jagoda
jagoda / async_error.js
Last active December 27, 2015 13:49
Demonstrate non-intuitive `async.waterfall` behavior.
var async = require("async");
function asyncExample (callback) {
console.log("asynchronous error");
async.waterfall(
[
function (next) {
console.log("throwing error");
next(new Error("Fail!"));
},
@jagoda
jagoda / both.js
Last active August 29, 2015 13:56
Factories and Constructors
function makeInstance (constructor, context) {
return context === global || context === undefined ?
Object.create(constructor.prototype) :
context;
}
function Rectangle (length, width) {
var rectangle = makeInstance(Rectangle, this);
rectangle.area = function () {
@jagoda
jagoda / constructor.js
Created February 23, 2014 19:47
constructor pattern
function Rectangle (length, width) {
this._length = length;
this._width = width;
}
Rectangle.prototype.area = function () {
return this._length * this._width;
}
function Square (side) {
@jagoda
jagoda / factory.js
Created February 23, 2014 19:47
factory pattern
function rectangle (length, width) {
var rectangle = Object.create(null);
rectangle.area = function () {
return length * width;
};
return rectangle;
}
@jagoda
jagoda / .eslintrc
Created January 11, 2016 01:18
ESLint config
{
"env": {
"es6": true,
"node": true
},
"rules": {
"comma-dangle": [ 2, "never" ],
"no-cond-assign": [ 2, "always" ],
"no-console": 2,
@jagoda
jagoda / alpha_request.js
Last active June 11, 2018 23:35
Alpha Request
const Alpha = require('@lifeoic/alpha');
async function performRequests () {
const client = new Alpha();
const httpResponse = await client.get('http://example-service/some/path');
const lambdaResponse = await client.get('lambda://example-function:some-alias/some/path');
console.log(`http service responded with ${httpResponse.status}`);
console.log(`lambda service responded with ${lambdaResponse.status}`);
}
@jagoda
jagoda / alpha_test.js
Created June 11, 2018 23:35
Alpha Test
const Alpha = require('@lifeomic/alpha');
const lambda = require('./path/to/lambda/module');
const test = require('ava');
test.beforeEach((test) => {
test.context.client = new Alpha(lambda.handler);
});
test('The lambda returns 200', async (test) => {
const response = await test.context.client.get('/');