Skip to content

Instantly share code, notes, and snippets.

View karlpokus's full-sized avatar
💭
certified rubber duck

carl-fredrik grimberg karlpokus

💭
certified rubber duck
View GitHub Profile
@karlpokus
karlpokus / encoder.md
Created September 13, 2016 14:22
encode urls in js. Safe characters and what-not.

encode URLs

src

TL;DR

  • encodeURI() will not encode ~!@#$&*()=:/,;?+' Use on entire string
  • encodeURIComponent() will not encode: ~!*()' Use on tricky values. Will ruin = and &
@karlpokus
karlpokus / bash_boss.sh
Last active February 20, 2017 16:41
bash like a baos!
# cd from ls
cd `ls | grep bengt`
# ls by mtime
ls -t
# page through a file
less filename
# processes
top
ps -aux
# write file
@karlpokus
karlpokus / phishing_test.md
Created September 9, 2016 07:20
phishing test @Company - implementation details

Inspired by this -> https://insight.duo.com/

Simple usage

  1. get a list of e-mail addresses
  2. send e-mails with personal URL from hashed e-mail address
  3. log each requests (ts, url, user) on server

result

  • e-mail addresses of personel who clicked the link
  • % personel who clicked
@karlpokus
karlpokus / npm_link.md
Last active July 13, 2022 15:32
npm link for dummies
@karlpokus
karlpokus / bindAll.js
Created August 29, 2016 11:54
Pass 1+ objects to bind all functions to it - creating a useful <this>
// 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]') {
@karlpokus
karlpokus / curl.sh
Last active June 4, 2024 19:39
bash curl API
#!/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>
@karlpokus
karlpokus / filterByRegex.js
Created August 14, 2016 08:56
Array filter by regex and some weird arguments applied
var matches = ["sun", "clouds", "rain", "hail", "snow"].filter(/./.test, /i/);
@karlpokus
karlpokus / fongo.js
Created July 7, 2016 08:44
fongo in js - stub mongo for testing [WIP]
// 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
@karlpokus
karlpokus / iife.js
Created July 7, 2016 06:09
IIFE - modular pattern in JS
// 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;
@karlpokus
karlpokus / mute.js
Last active July 6, 2016 08:40
Mute and capture console.log in the browser
// 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/