Skip to content

Instantly share code, notes, and snippets.

View h2non's full-sized avatar

Tom h2non

  • Dissident
  • Decentralized
View GitHub Profile
@h2non
h2non / constructor-arguments.js
Created February 14, 2014 21:47
JavaScript constructor with dynamic arguments that behaves like using the "new" operator
function MyClass(/* dynamic constructor arguments, meta-programming rules! */) {}
MyClass.prototype.method = function () {}
MyClass.create = function () {
var instance = Object.create(MyClass.prototype)
MyClass.apply(instance, arguments)
return instance
}
@h2non
h2non / Dployrfile.yml
Created April 29, 2014 11:00
Dployrfile example
default:
attributes:
index: 1
dployr:
attributes:
name: "dployr"
prefix: dev
private_key_path: ~/pems/cert.pem
username: john
@h2non
h2non / nar-static-http-app.md
Last active August 29, 2015 14:03
Create an executable binary-like nar archive based on a static web application with an embedded HTTP server

nar webapp howto

Create a fully self-contained executable of a web application with an embedded HTTP server using nar

Install nar as global package (you must have node.js already installed in your system)

$ npm install -g nar
@h2non
h2non / uuid.js
Last active August 29, 2015 14:06
Time-based UUID v4 compliant generator (RFC4122 compliant)
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) uuid += "-"
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16)
}
return uuid
}
@h2non
h2non / base64-utf8-decode.js
Created October 28, 2014 14:42
Base64 UTF8 native decoding in browsers
function base64UTF8Decode(str) {
return unescape(decodeURIComponent(window.atob(str)))
}
(function (global) {
'use strict';
/*\
|*|
|*| Base64 / binary data / UTF-8 strings utilities
|*|
|*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|*|
\*/
@h2non
h2non / jshint-directives-node.js
Last active August 29, 2015 14:09
JSHint directives for node.js projects
{
"node": true,
"browser": false,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
@h2non
h2non / .editorconfig
Created November 12, 2014 14:26
Editorconfig for package.json
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
@h2non
h2non / ffmpeg-install-osx.sh
Last active August 29, 2015 14:14
Install ffmpeg and common video/audio encoding shared libraries in OSX
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-libogg
@h2non
h2non / debug.go
Last active August 29, 2015 14:18
package bimg
import (
"github.com/dustin/go-humanize"
. "github.com/tj/go-debug"
"runtime"
"strconv"
"time"
)