Skip to content

Instantly share code, notes, and snippets.

View ivoputzer's full-sized avatar
:octocat:

Ivo von Putzer Reibegg ivoputzer

:octocat:
View GitHub Profile
@ivoputzer
ivoputzer / luhn.js
Created February 27, 2014 09:46
Luhn check-digit and validation
String.prototype.toLuhn = function() {
var sum = 0
this.replace(/\D+/g,'').replace(/[\d]/g, function(c, p, o){
sum += [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]][(o.length-p) & 1][parseInt(c, 10)]
})
return this + ((10 - sum % 10) % 10)
}
@ivoputzer
ivoputzer / http.proxy.js
Last active August 29, 2015 13:57
Node http proxy
var http = require('http')
http.createServer(function(req, res) {
var proxy = http.get({ hostname: process.argv[process.argv.length -1], port: 80, path: req.url }, function(r) {
r.pipe(res)
})
}).listen(8080)
@ivoputzer
ivoputzer / gist:ed901d38ef184e51bd08
Created May 11, 2014 18:29
angular.js filter for byte format
.filter('bytes', [function(){
return function bytes(a, b, c, d, e){
return (b=Math,c=b.log,d=1e3,e=c(a)/c(d)|0,a/b.pow(d,e)).toFixed(2) + (e?'kMGTPEZY'[--e]+'B':'Bytes')
}
}])
@ivoputzer
ivoputzer / ngFile.js
Last active August 29, 2015 14:08
directive to fix file-input field's model binding in angular
.directive('ngFile', ['$parse', function($parse){
return {
restrict: 'A',
require: 'ngModel',
link: function($scope, $element, attrs){
$element.bind('change', function(event){
$scope.$apply(function($scope){
$parse(attrs.ngModel).assign($scope, event.target.files)
})
})
@ivoputzer
ivoputzer / ngFileQueue.js
Created October 25, 2014 23:25
applying `ngFile.js` but pushing files to model
.directive('ngFile', ['$parse', function($parse){
return {
restrict: 'A',
require: 'ngModel',
link: function($scope, $element, attrs){
$element.bind('change', function(event){
$scope.$apply(function($scope){
Array.prototype.push.apply($parse(attrs.ngModel)($scope), event.target.files || [])
})
})
@ivoputzer
ivoputzer / com.docker.boot2docker.plist
Last active August 25, 2015 22:03 — forked from johnantoni/com.docker.boot2docker.plist
run boot2docker on system startup - Mac OSX - Yosemite
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.docker.boot2docker</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/boot2docker</string>
<string>up</string>
@ivoputzer
ivoputzer / app.coffee
Last active September 2, 2015 23:23
express4.router isolation testing
# app/app.coffee
express = require 'express'
app = express()
app.use require 'controllers/status'
app.listen(80)
@ivoputzer
ivoputzer / combine.coffee
Created October 16, 2015 12:51
combine.js
module.exports = (keys, values) -> keys.reduce ((p, v, i) -> p[v] = values[i]; p), {}
@ivoputzer
ivoputzer / scrolledIntoView.js
Last active September 8, 2019 22:16
scrolledIntoView.js
function scrolledIntoView(element) {
var rect = element.getBoundingClientRect()
, h = (window.innerHeight || document.documentElement.clientHeight)
, w = (window.innerWidth || document.documentElement.clientWidth)
, verticalVisibility = (rect.top <= h) && ((rect.top + rect.height) >= 0)
, horizontalVisibility = (rect.left <= w) && ((rect.left + rect.width) >= 0)
return verticalVisibility && horizontalVisibility
}