Skip to content

Instantly share code, notes, and snippets.

View kevinswiber's full-sized avatar
🍄
lizard person

Kevin Swiber kevinswiber

🍄
lizard person
View GitHub Profile
@kevinswiber
kevinswiber / example.js
Last active February 15, 2020 14:39
Quick service locator in JavaScript.
var ServiceLocator = require('./service_locator');
var locator = new ServiceLocator();
var Greeter = function(message) {
this.message = message;
};
Greeter.prototype.greet = function() {
console.log(this.message);
};
@kevinswiber
kevinswiber / thoughts.md
Created November 6, 2013 08:35
Some thoughts on RFC 6902 - JavaScript Object Notation (JSON) Patch

Thoughts on JSON Patch

Introduction

JSON Patch is a media type developed to take advantage of the HTTP PATCH method. It includes operations such as add, remove, replace, copy, move, and test. Below is a first reaction to reading the specification. Note that the author has not attempted a real implementation of JSON Patch, which would certainly provide a more thorough analysis and different perspective.

Benefits

  1. The JSON Patch specification provides an actual media type to use with PATCH. This enables the PATCH method to be usable across client-server implementations. It's a real attempt at solving the partial update problem in Web APIs.
  2. JSON Patch documents allow shallow and nested object updates.
@kevinswiber
kevinswiber / Dockerfile-erlang-r16b02
Created December 1, 2013 22:47
Dockerfiles for running Logplex in a container.
FROM ubuntu
MAINTAINER Kevin Swiber <[email protected]>
RUN apt-get install -y build-essential libncurses5-dev openssl libssl-dev fop xsltproc unixodbc-dev wget
RUN mkdir /tmp/erlang && cd /tmp/erlang
RUN wget http://erlang.org/download/otp_src_R16B02.tar.gz && \
tar zxvf otp_src_R16B02.tar.gz && \
cd otp_src_R16B02 && \
./configure && make && make install
@kevinswiber
kevinswiber / docker_kill_reset_iptables.sh
Created December 2, 2013 21:34
Kill Docker containers and reset iptables
docker ps | grep node | awk '{ print $1 }' | xargs docker stop
docker ps -a | grep node | awk '{ print $1 }' | xargs docker rm
sudo iptables -S | grep docker0.*ACCEPT | awk '{ gsub("-A", "sudo iptables -D", $0); print $0 }' | xargs -0 /bin/bash -c
@kevinswiber
kevinswiber / gist:7774301
Created December 3, 2013 18:05
Docker - print container names and IDs.
docker ps -q | xargs docker inspect | json -a Name ID | awk '{ print substr($0, 2); }' | column -t
@kevinswiber
kevinswiber / root.feature
Last active August 29, 2015 13:55
Exploring hypermedia aware acceptance testing.
Feature: Root Resource
As an API client
I want to see the root resource
So that I have a starting point to complete my task.
Scenario: Request the root
Given an anonymous client
When I make a GET request to /
Then I should get a 200 status code
And the content type should be JSON
@kevinswiber
kevinswiber / npm-debug.log
Created February 2, 2014 17:17
Can't publish new packages to NPM.
0 info it worked if it ends with ok
1 verbose cli [ '/Users/kevin/nvm/v0.10.17/bin/node',
1 verbose cli '/Users/kevin/nvm/v0.10.17/bin/npm',
1 verbose cli 'publish' ]
2 info using [email protected]
3 info using [email protected]
4 verbose publish [ '.' ]
5 verbose cache add [ '.', null ]
6 verbose cache add name=undefined spec="." args=[".",null]
7 verbose parsed url { protocol: null,
@kevinswiber
kevinswiber / app.js
Last active August 29, 2015 13:56
Elroy app with promises.
var Scientist = require('../scientist');
var Nightlight = require('./nightlight');
var wrap = require('./elroy_promise');
var HelloApp = module.exports = function() {
this.name = 'hello';
};
HelloApp.prototype.init = function(elroy) {
elroy = wrap(elroy);
@kevinswiber
kevinswiber / fake_socket.js
Last active August 29, 2015 13:56
Fake net.Socket with HTTP
var Duplex = require('stream').Duplex;
var util = require('util');
var FakeSocket = module.exports = function() {
Duplex.call(this);
this.source = new BufferSource();
this.on('finish', function() {
this.source.state = 'ready';
@kevinswiber
kevinswiber / buffer_stream.js
Last active August 29, 2015 13:56
Buffered Duplex Stream
var Duplex = require('stream').Duplex;
var util = require('util');
var BufferStream = module.exports = function() {
Duplex.call(this);
this.source = new BufferSource();
this.on('finish', function() {
this.source.state = 'ready';