Skip to content

Instantly share code, notes, and snippets.

View zackferrofields's full-sized avatar

Zack Ferro-Fields zackferrofields

View GitHub Profile
@zackferrofields
zackferrofields / gulpfile.js
Last active September 19, 2015 19:33
Inline JavaScript (ES6) unit-tests with node, gulp, speckjs, babel & tape
require('babel-core/register');
var babel = require('babel-core');
var gulp = require('gulp');
var speckjs = require('speckjs');
var tape = require('tape');
var through = require('through2');
function requireFromBuffer(buffer) {
var m = new module.constructor();
m.paths = module.paths;
@zackferrofields
zackferrofields / app_Dockerfile
Last active October 25, 2015 18:43
Docker compose nginx, node & redis
// ./app/Dockerfile
FROM node:4.1.0
WORKDIR /src/app
ADD package.json package.json
RUN npm install
@zackferrofields
zackferrofields / server.js
Created December 17, 2015 12:30
Rx.Observable Node HTTP server
var http = require('http');
var Rx = require('rx');
function observableServer(server) {
return Rx.Observable.fromEventPattern(
server.addListener.bind(server, 'request'),
server.removeListener.bind(server, 'request'),
(req, res) => ({req, res})
).takeUntil(Rx.Observable.fromEvent(server, 'close'));
}
@zackferrofields
zackferrofields / index.js
Last active January 8, 2016 13:54
Node static HTTP server
const http = require('http');
const fs = require('fs');
const path = require('path');
const url = require('url');
const PORT = 8000;
http.createServer((req, res) => {
const pathname = url.parse(req.url).pathname;
const isStaticFile = !!path.extname(pathname);
const filePath = path.join(__dirname, isStaticFile ? path.join('static', pathname) : 'views/index.html');
@zackferrofields
zackferrofields / server.js
Last active September 12, 2016 16:23
Node static file server
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 8000;
const filePath = path.join(__dirname, 'index.html');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream(filePath)
.on('data', data => res.write(data))
@zackferrofields
zackferrofields / slack.py
Last active March 31, 2018 01:46
AWS CodeDeploy trigger Lambda Slack message
'''
Follow these steps to configure the webhook in Slack:
1. Navigate to https://<your-team-domain>.slack.com/services/new
2. Search for and select "Incoming WebHooks".
3. Choose the default channel where messages will be sent and click "Add Incoming WebHooks Integration".
4. Copy the webhook URL from the setup instructions and use it in the next section.
@zackferrofields
zackferrofields / .lambci.js
Last active March 20, 2017 18:03
Lambci yarn test
module.exports = {
cmd: 'nave use 7 bash -c "sh lambci_test.sh"'
}
@zackferrofields
zackferrofields / autoScroll.js
Last active February 12, 2018 20:22
Stateless (almost) react scroll to on `componentDidMount`
import { createElement } from 'react';
import { compose } from 'ramda';
import { lifecycle, withProps } from 'recompose';
const enhance = compose(
lifecycle({ componentDidMount() {
this.refs.node.scrollIntoView({block: 'end', behavior: 'smooth'});
} }),
withProps({ ref: 'node' }),
);
@zackferrofields
zackferrofields / docker_cleanup.sh
Last active May 10, 2017 13:12
Docker clean up commands
#!/bin/bash
# stop running containers
docker ps -q | xargs docker stop
# force remove all containers
docker ps -a -q | xargs docker rm -f
# force remove all untagged images
docker images -q --filter dangling=true | xargs docker rmi -f
@zackferrofields
zackferrofields / debug_node.sh
Last active August 15, 2017 11:41
Chrome DevTools debug, a reverse-proxy NodeJS Docker container
#!/bin/bash
# Chrome DevTools debug,
# a reverse-proxy NodeJS Docker container
#
# Example docker-compose file
#
# version: "3"
# services:
# proxy: