Skip to content

Instantly share code, notes, and snippets.

View flesch's full-sized avatar

John Flesch flesch

View GitHub Profile
@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
@flesch
flesch / setSize.js
Created October 27, 2009 21:26
Set a window's size
function setSize(w, h) {
if (window.name && w && h) {
var innerWidth, innerHeight, width = Math.floor(w), height = Math.floor(h);
innerWidth = (window.innerWidth || document.documentElement.clientWidth);
innerHeight = (window.innerHeight || document.documentElement.clientHeight);
window.resizeBy(Math.floor(width-innerWidth), Math.floor(height-innerHeight));
window.moveTo(Math.floor((screen.availWidth/2)-(width/2)), Math.floor((screen.availHeight/2)-(height/2)));
}
}
@flesch
flesch / benchmarking.php
Created February 25, 2010 20:16
PHP Benchmarking
<?php
function utime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
// Start benchmarking.
$start = utime();
@flesch
flesch / sprintf.as
Created February 25, 2010 21:46
Very simple sprintf() implementation
function sprintf(){
var args = Array.prototype.slice.call(arguments), f:Array = [], str = args.shift().split("%s");
while (str.length) {
f.push(str.shift(), args.shift() || "");
}
return f.join("");
}
trace(sprintf("Hello %s, how ya %s?", "motherf*cker", "durin"));
@flesch
flesch / guid.js
Created August 3, 2010 17:38
Token
function guid() {
function hex(len) {
var s = '', n = len || 4;
while (s.length < n) {
s += (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
return s.substr(0, n);
}
return [hex(8), hex(4), hex(4), hex(4), hex(12)].join('-');
}
@flesch
flesch / get_http_status_header.php
Created August 10, 2010 14:31
Return the HTTP Status code as an integer.
<?php
function get_http_status_header($url) {
preg_match('/[0-9]{3}/', array_shift(get_headers($url)), $matches);
return (int) array_shift($matches);
}
?>
@flesch
flesch / boilerplate.php
Created November 19, 2010 04:11
A quick PHP/HTML5 boilerplate.
<?php
define('APP_ROOT', pathinfo(implode('/', array_slice(explode('/', $_SERVER['PHP_SELF']), 1, 2)), PATHINFO_DIRNAME));
define('DOCUMENT_ROOT', str_replace('/.', '', sprintf('%s/%s', $_SERVER['DOCUMENT_ROOT'], APP_ROOT)));
define('SERVER_NAME', preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME']));
define('SERVER_URL', sprintf('http://%s/%s', SERVER_NAME, APP_ROOT));
function utime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
@flesch
flesch / boilerplate.html
Created November 19, 2010 04:05
A quick HTML5 boilerplate
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>fles.ch</title>
<!--[if IE]>
<script src="http://static.fles.ch/js/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="http://static.fles.ch/css/reset-min.css" />
<style>
@flesch
flesch / router.php
Created December 3, 2010 03:49
Simple PHP router.
<?php
/*******************************************************************************
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
*******************************************************************************/