Instantly share code, notes, and snippets.

View encryption.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.

View gist:c8c01fcd242799c262fc

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

View NASMx86: Allocate heap memory
; 1 2 3 4 5 6 7
;| |
;| Example using brk() system call for dynamic memory allocations. |
;| |
;| DON'T CONFUSE that brk() used in C Function is different with brk() |
;| systemcall (systemcall 45 for x86 ASM). |
;| |


int foo(int a, int b) {
  return a + b;

function whitespace

The following looks much more like a "package" without the extra space:

app.get('/', function(req, res){
  res.send('Hello World');

app.get('/', function(req, res) {
View hmm.js
var test =
['label0', 100, 200, 300, 400, 500],
['label0', 200, 100, 400, 300, 500],
['label1', 100, 100, 100, 100, 100],
['label1', 100, 100, 100, 100, 100],
['label2', 0, 0, 0, 0, 0],
['label2', 0, 1, 1, 0, 0],

The Client-Side Rendering Problem

The core problem with UI rendering boils down to these two questions:

  1. How do you know when something has changed?
  2. How do you most optimally update the UI with those changes?

What has changed?

There are several implementations that can tell you what has been changed, some of which are:

View index.js
var vs = document.getElementById('vs').textContent;
var fs = document.getElementById('fs').textContent;
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('experimental-webgl', {
alpha: false,
antialias: true,
premultipliedAlpha: false,
stencil: true
View gist:9042712

HLS streaming from node

Provided that you already have a file or stream segmenter generating your .m3u8 playlist and .ts segment files (such as the ffmpeg 'hls' muxer), this little node server will serve up those files to an HLS compatible client (e.g. Safari). If you're using node for your streaming app already, this obviates the need to serve the HLS stream from a separate web server.

loosely based on

// loosely based on
// requires node.js >= v0.10.0
// assumes that HLS segmenter filename base is 'out'
// and that the HLS playlist and .ts files are in the current directory