Skip to content

Instantly share code, notes, and snippets.

package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@wonderdogone
wonderdogone / Dockerfile
Created December 27, 2015 01:52 — forked from thom-nic/Dockerfile
Dockerfile that attempts to run the app as non-root user. This creates a `node` user & sets permissions on app files. Note you cannot `chown` files in a docker 'volume' during the build process, but you can at runtime (as part of your `CMD`) but in that case you can't use the `USER` command to change the UID before `CMD` runs.
###
# Node.js app Docker file
#
# Some basic build instructions:
# ```
# # you should delete node_modules b/c you don't want that copied during 'ADD'
# docker build -t thom-nic/node-bootstrap .
# # run a shell in the container to inspect the environment (as root):
# docker run --rm -itu root thom-nic/node-bootstrap /bin/bash
# ```
@wonderdogone
wonderdogone / Dockerfile
Created November 29, 2015 21:06 — forked from aaronjudd/Dockerfile
Meteor Dockerfile with imagemagick and phantomjs
############################################################
# Builds a Meteor 0.9.x+ application Docker image
#
# See: http://docs.docker.io/
#
# Important: Best to run from a clean directory that hasn't had meteor run in it.
# Important: packages/<pkg>/.npm and .build* should not exist
#
# Example usage:
# cd appdir #in app dir
class AutoComponent extends React.Component {
constructor() {
super()
var cls = this.constructor
var methods, methodName
while (cls !== AutoComponent) {
methods = Object.getOwnPropertyNames(cls.prototype)
for (var i in methods) {
methodName = methods[i]
if (methodName.match(/^on[A-Z]/) !== null) {
async.series([
function(callback){
// do some stuff ...
callback(null, 'one');
},
function(callback){
// do some more stuff ...
callback(null, 'two');
}
],
@wonderdogone
wonderdogone / new-promises-fallback.js
Created October 29, 2015 18:20 — forked from joepie91/new-promises-fallback.js
Fallback values in promise chains
/* UPDATED: This example has been changed to use the new object predicates, that were
* introduced in Bluebird 3.0. If you are using Bluebird 2.x, you will need to use the
* older example below, with the predicate function. */
var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));
Promise.try(function(){
return fs.readFileAsync("./config.json").then(JSON.parse);
}).catch({code: "ENOENT"}, function(err){
const cluster = require('cluster');
if (cluster.isMaster) {
let router = zmq.socket('router').bind('tcp://127.0.0.1:5433');
// forward messages between router and dealer
router.on('message', function() {
@wonderdogone
wonderdogone / flattening.js
Last active August 29, 2015 14:28 — forked from joepie91/flattening.js
Promise flattening
doAsyncThing.then(function(result){
return doAnotherAsyncThing().then(function(result){
return doYetAnotherAsyncThing().then(function(result){
console.log("Done!");
});
});
}).catch(function(err){
/* This is where errors from *any* of the above promises end up. */
});
meta = {
module : {
author : author,
title : title,
descrip : description,
clips : [{clip : {$ : {href : 'test'},
description : 'test'
}}]
}
}
app.get("/user/:userid", function (req, res, next) {
var id = parseInt(req.params.userid);
if (id === 'John') {
next();
} else {
//do something with the none John user id
}
});