encodeURI()
will not encode~!@#$&*()=:/,;?+'
Use on entire stringencodeURIComponent()
will not encode:~!*()'
Use on tricky values. Will ruin=
and&
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cd from ls | |
cd `ls | grep bengt` | |
# ls by mtime | |
ls -t | |
# page through a file | |
less filename | |
# processes | |
top | |
ps -aux | |
# write file |
Inspired by this -> https://insight.duo.com/
- get a list of e-mail addresses
- send e-mails with personal URL from hashed e-mail address
- log each requests (ts, url, user) on server
- e-mail addresses of personel who clicked the link
- % personel who clicked
Submit PR via https://docs.npmjs.com/cli/link
- You want B to depend on A but
- A is not on npm (or it is - but you don't feel like publishing after each fix)
- While standing in A
npm link
makes a global package of A. Verify bynpm ls -g --depth=0
. - A can then be used by B by doing
npm link A
while inside B. Verify bynpm ls --depth=0
.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem: Callbacks are called with the window object as <this> | |
// Solution: Bind all functions to their object | |
// An implementation of http://underscorejs.org/#bindAll | |
// Demo -> http://codepen.io/KarlPokus/pen/Lkwqyj | |
function bindAll(x) { | |
var wat = Object.prototype.toString; | |
if (wat.call(x) === '[object Object]') { | |
x = [x]; | |
} | |
if (wat.call(x) === '[object Array]') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# simple GET | |
curl <url> | |
# POST w json | |
curl -X POST -H "Content-Type: application/json" -d '{"data":"POST with json"}' <url> | |
# POST w urlencoded | |
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'foo=1&boo=2' <url> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var matches = ["sun", "clouds", "rain", "hail", "snow"].filter(/./.test, /i/); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Like this -> https://github.com/fakemongo/fongo | |
// Based on this wrapper API from the shell | |
db[collectionName].query({selectors}, {projections}, cb(err, data)); | |
// Pass dummy data to constructor | |
var db = new Fongo({ | |
collections: [], | |
users: [ // should match to array above | |
{} // simple objects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from http://appendto.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/ | |
(function(foo, $, undefined){ // parameters | |
// private var in closure | |
var data = [1, 2, 3]; | |
// public fn | |
foo.moo = function() { | |
console.log(data); | |
} | |
return foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// completely mute | |
console.log = function() {}; | |
// captured data in log | |
var log = []; | |
console.log = function() { | |
log.push([].slice.call(arguments)); | |
}; | |
// fancy namespaced version. Demo -> http://codepen.io/KarlPokus/pen/rLwXQX/ |