Skip to content

Instantly share code, notes, and snippets.

@andineck
andineck / file.ps1
Created April 22, 2015 13:04
powershell read write file
$filePath = "test.txt"
# write append to file
echo 'halloo' >> $filePath
# write empty file
echo $null > $filePath
@andineck
andineck / buffer-gt-0x80.js
Last active August 29, 2015 14:18
Buffer.toString() encoding
var assert = require('assert');
var buf, buf2;
buf = new Buffer([0x00, 0x41, 0x7f]);
buf2 = new Buffer(buf.toString());
//console.log(buf, buf2);
// -> <Buffer 00 41 7f> <Buffer 00 41 7f>
assert(buf2.equals(buf), 'buffer with normal acii chars can be converted to string and back');
assert.equal(buf2.length, 3);
@andineck
andineck / arguments.js
Created April 2, 2015 14:19
javascript arguments
// turn function arguments into an array
var args = [].slice.apply(arguments)
@andineck
andineck / git-check.sh
Created April 2, 2015 11:57
git check
# add `git check ` alias for git add ALL dry-run
git config --global alias.check '!git add -A -n'
@andineck
andineck / prop.js
Created April 1, 2015 13:23
javascript adding properties to function, string and array
function echo(input) { console.log(input);}
undefined
echo('hallo')
VM304:2 hallo
undefined
// you can add an attribute to a function
echo.prop = 'echooo'
"echooo"
echo.prop
"echooo"
@andineck
andineck / 1 git shortcut.md
Last active November 22, 2016 08:03
git shortcut save

git shortcuts

@andineck
andineck / cookie.js
Last active August 29, 2015 14:17
cookie expires vs max-age
@andineck
andineck / shadow.js
Created March 16, 2015 20:34
variable shadowing
var a = 1;
//undefined
function showA () { var a = 2; console.log(a);}
//undefined
a
//1
showA()
//2
a
//1
@andineck
andineck / NodeList.js
Created February 17, 2015 07:28
Iterate over NodeList with querySelectorAll
// test
var els = document.querySelectorAll('[data-block]');
// make blocks global for testing purposes
blocks = Array.prototype.slice.call(els);
var obj = blocks;
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key], obj[key].classList);
});
@andineck
andineck / index.js
Created February 11, 2015 16:01
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Rebuild to run it on the right
var level = require('level-browserify')
// 1) Create our database, supply location and options.
// This will create or open the underlying LevelDB store/Indexedb Database
var db = window.levelDB = level('./mydb')
// 2) put a key & value
db.put('name', 'Level', function (err) {