Skip to content

Instantly share code, notes, and snippets.

View flesch's full-sized avatar

John Flesch flesch

View GitHub Profile
@flesch
flesch / LICENSE.txt
Created August 22, 2012 21:28 — forked from 140bytes/LICENSE.txt
str2seq: Text to Binary
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 John Flesch <http://fles.ch/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@flesch
flesch / LICENSE.txt
Created August 22, 2012 21:29 — forked from 140bytes/LICENSE.txt
seq2str: Binary to Text
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 John Flesch <http://fles.ch/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@flesch
flesch / README.md
Last active October 11, 2015 08:57
Cookie Helper
cookie("user", "flesch", { expires:(new Date(new Date() * 1 + 6E10)).toGMTString(), path:"/"});
cookie("user");

Based off work from https://gist.github.com/1058674

@flesch
flesch / console.js
Created October 26, 2012 15:44
console.log
if (typeof window.console === "undefined") {
window.console = {
log: function() {
alert(Array.prototype.slice.call(arguments).join(", "));
}
}
}
@flesch
flesch / basic-auth.js
Last active July 27, 2022 12:39
HTTP Basic Authentication with Express, without express.basicAuth.
var express = require("express");
var app = express();
app.get("/restricted", function(req, res, next){
// Grab the "Authorization" header.
var auth = req.get("authorization");
// On the first request, the "Authorization" header won't exist, so we'll set a Response
// header that prompts the browser to ask for a username and password.
var UpperCaseStream = function(){
this.readable = true;
this.writable = true;
};
require("util").inherits(UpperCaseStream, require("stream"));
UpperCaseStream.prototype._transform = function(data){
data = data ? data.toString() : "";
this.emit("data", data.toUpperCase());
@flesch
flesch / cluster.js
Last active January 2, 2016 03:38
eval $([ -f .env ] && cat .env) node cluster.js
var cluster = require('cluster')
, express = require('express')
, app = express()
, cpus = require('os').cpus().length;
app.get('/', function(req, res, next){
res.json({ "env":process.env.NODE_ENV || "development", "pid":cluster.worker.process.pid });
});
if (cluster.isMaster) {
@flesch
flesch / deprecate-console-test.js
Created November 20, 2014 17:44
Deprecate `console.log` in favor of node-bunyan.
var deprecate = require('depd')('bunyan')
, bunyan = require('bunyan')
;
// Bunyan logger used by the app.
var logger = bunyan.createLogger({ name:'app', level:'debug' });
// Bunyan logger to catch only the console.
var depdconsole = bunyan.createLogger({ name:'console', level:'warn' });
@flesch
flesch / mkv2mp4.sh
Last active August 29, 2015 14:10 — forked from ravnoor/mkv2mp4.sh
Convert Matroska MKV to iTunes compatible MP4 format for Airplay streaming on AppleTV. (http://git.io/mkv2mp4)
#!/bin/bash
# brew install libav
# curl -fsSL http://git.io/mkv2mp4sh | sh
for mkv in *.mkv; do
mp4="$(basename --suffix=.mkv "$mkv").mp4"
avconv -i "$mkv" -c:v copy -c:a aac -strict experimental -threads auto "$mp4"
done