Skip to content

Instantly share code, notes, and snippets.

@bowin
bowin / node.js PassThrough stream.md
Last active November 15, 2022 00:02
Node.js Stream PassThrough Usage
const {PassThrough} = require('stream')
const fs = require('fs')

const d = new PassThrough()  

fs.createReadStream('tt2.js').pipe(d)  // can be piped from reaable stream

d.pipe(process.stdout)                 // can pipe to writable stream 
d.on('data', console.log) // also like readable
@adammw
adammw / client.js
Last active September 13, 2022 02:33
simple-peer / socket.io test
var Peer = require('simple-peer');
var io = require('socket.io-client');
var debug = require('debug')('client');
var socket = io.connect();
var peers = {};
var useTrickle = true;
socket.on('connect', function() {
debug('Connected to signalling server, Peer ID: %s', socket.id);
});
@oroce
oroce / app.js
Created June 17, 2014 08:37
parse csp report in express
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// chrome sends application/csp-report
// firefox sends application/json
// it seems chrome is doing it well: https://w3c.github.io/webappsec/specs/content-security-policy/
app.use(bodyParser.json({
type: ['json', 'application/csp-report']
}));
@cowboy
cowboy / github_post_recieve.php
Created October 11, 2010 02:04
GitHub PHP webhook to auto-pull on repo push
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ( $_POST['payload'] ) {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi