Skip to content

Instantly share code, notes, and snippets.

###
Lazy load an object.
###
req.object = (type, id, fn) ->
if typeof id is 'function'
fn = id
id = null
unless id?
object = new _Object(
website: req.website._id
private Bitmap rotateBitmap(Bitmap source, byte[] data) {
int exifOffset = Exif.getOrientation(data);
int rotation = this.rotation;
int rotate = 0;
if ((rotation < (270 + 45) && rotation > (270 - 45))) {
Log.e("BLIMP", "270 degrees ...");
rotate = -90;
} else if (rotation < (90 + 45) && rotation > (90 - 45)) {
Log.e("BLIMP", "90 degrees ...");
@domachine
domachine / Dockerfile
Created November 2, 2015 10:11
Dockerfile to run a couchapp with nodejs
FROM klaemo/couchdb:1.6
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
python build-essential git-core
# gpg keys listed at https://github.com/nodejs/node
RUN set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
@domachine
domachine / highland-router.js
Last active November 2, 2015 10:14
A simple hash-router in a functional reactive manner. Implemented in highland.
// Example for a reactive functional router implemented in highland.
var router = _.pipeline(
_.map(e => (parse(e.newURL).hash || '#').slice(1)),
_.map(path => routes.match(path)),
_.map(m => m.fn(m.params)),
// Make sure that the side-effect results are resetted.
_.flatMap(m => _([
{_location: window.location.hash, _view: null}
@domachine
domachine / nginx.conf
Created November 2, 2015 13:03
Couchapp nodejs nginx configuration
server { # simple reverse-proxy
server_name _;
listen 80 default_server;
location / {
proxy_pass http://app:5984;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
'use strict';
var net = require('net');
var multilevel = require('multilevel');
var level = require('level');
var db = level('db');
var server = net.createServer(con => {
con.pipe(multilevel.server(db, {
@domachine
domachine / mongoose-api.js
Last active December 11, 2015 15:40
A simple POC for a generic mongo json API
var express = require('express');
var mongoose = require('mongoose');
var error = require('http-errors');
require('./posts');
var api = express();
api.get('/:collection', (req, res, next) => {
let Model = getModel(req);
Model.access({
@domachine
domachine / flow_io.js
Last active February 2, 2016 09:46
Side-effect-free side effects
'use strict';
const assert = require('assert');
// Simple goal is to push out side-effects for testability
function liftMethod(ctx, method, opts) {
return lift(ctx[method], Object.assign({ ctx }, opts || {}));
}
function lift(fn, opts) {
function *myGenerator() {
const a = yield 2;
return a;
}
const it = myGenerator();
it.next(); // => { value: 2, done: false }
it.next('hello') // => { value: 'hello', done: true }
function performingIO(done) {
console.log('Heay IO ...');
setTimeout(() => done(42), 1000);
}
function *myGenerator() {
const a = yield { fn: performingIO };
return a;
}