Skip to content

Instantly share code, notes, and snippets.

View groundwater's full-sized avatar
:electron:
Performing Alchemy

Groundwater groundwater

:electron:
Performing Alchemy
View GitHub Profile
@groundwater
groundwater / Dockerfile
Last active December 23, 2015 12:18
Example NodeOS Dockerfile
# build nodeos from a bare image with only the linux kernel,
# and node binary installed
FROM nodeos/kernel
MAINTAINER Jacob Groundwater <groundwater@gmail.com>
# Environment variables passed to the init process and RUN commands
# setting BOOT=0 tells init to also exit after the shell process exists
ENV BOOT 0

Enumerating Unicorn Workers

Usage

unicorn -c unicorn.conf.rb
var fs = require('fs');
var pp = require('path');
var Readable = require('stream').Readable;
var Writable = require('stream').Writable;
var Transform = require('stream').Transform;
var util = require('util');
// divert strem objects by their type
var Switch = require('./switch' ).Switch;

Switch Stream

The switch stream multiplexes an readable stream across a series of writable streams. All streams operate in object mode, meaning read and write events emit whole objects instead of buffers.

Usage

var sw = new Switch();

Usage: asg-connect DESCRIPTION

The asg-connect command will search for Auto-Scale Group instances that match the description. The first instances will be selected and you will be SSH'd into it.

[14:50:32] trevnorris: groundwater: there are others that are "safer", whatever that's about :P
[14:50:41] trevnorris: but still almost as fast
[14:51:10] trevnorris: groundwater: are you creating an object just to attach these objects?
[14:51:38] groundwater: i will be
[14:51:43] trevnorris flogs github
[14:52:02] groundwater: right now i'm actually converting between c++ / js land but that's proving to be a losing strategy
[14:52:47] groundwater: and i'm just playing around with various approaches to find the best fit
[14:52:59] trevnorris: groundwater: then the actual proper way to do this is create an ObjectTemplate, set the InternalFieldCount = 1
[14:53:21] trevnorris: then use SetAlignedPointerInInternalfield
[14:53:43] trevnorris: oy, again. SetAlignedPointerInInternalField (int index, void *value)

I very often automate tasks using bash, a Makefile, or some other means. By far the best advice I can give anyone is to make your tasks idempotent. Let me say that again:

make your tasks idempotent

Having said that, it can be difficult when there are sub-tasks that should only be run once. Here is my small life-hack around that:

  1. check for the existence of a dot-file, e.g. .db-create-tables

Notes

  • virtualbox additions need to be installed in the global zone, then mount privileges need to be given to the guest zone using fs_allowd. The guest zone then mounts the virtualbox shared directory.
  • do not give the VM direct access to the virtualbox network, create an internal network to SmartOS and use ipnat to forward traffic internally.
  • once ipnat is forwarding traffic, forwarded ports from virtualbox will be redirected to the guest zone always
  • unpack the virtualbox guest additions for Solaris tools with pkgtrans VBoxSolarisAdditions.pkg ~/tmp
#!/usr/bin/env ruby
require 'json'
dat = {}
STDIN.read.split("\n")[4..-1].each do |line|
split = line.split(':')
if split.length > 1
lhs = split[1].strip.split(/\s+/)
if lhs.length > 1
@groundwater
groundwater / SSE.md
Last active December 18, 2015 00:48

Server-Sent Events

I recommend using SSEs like an event-stream only. Do not send data through the stream, only events the client may be interested in. Clients can obtain data they are interested in by making additional HTTP calls to the server.

This keeps the data accessible via HTTP; it does not shard our API into two pieces, one HTTP-based, and one websocket based. We can check any of our endpoints with CURL, and all our routes are stateless. Even our event-stream is relatively stateless, because the server can fire-and-forget events as they occur.

Websockets are fragile. Their protocol is complciated, and the most popular websocket library socket.io is prone to memory leaks. Websockets do not cross proxies well, and debugging websocket issues is a large effort.