Skip to content

Instantly share code, notes, and snippets.

@drslump
drslump / Dockerfile
Created June 12, 2017 16:29
telepresence docker vpn network
FROM ubuntu:xenial
# Install some required base software
RUN apt-get update
RUN apt-get install -y curl sudo iptables
# Install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x kubectl
RUN mv ./kubectl /usr/local/bin/kubectl
@drslump
drslump / httpmock.md
Created April 30, 2016 08:51
idea about an http mock server

HTTP Mock

HTTP server to provide configurable mock responses when automating complex scenarios.

Configuring the mocks

Mock logic is not hardcoded into the server, instead it's provisioned just before starting the automated scenario. For that a special endpoint is provided to instruct the server how it should behave.

proc djb2 { {input ""} {result 5381} } {
foreach c [split $input ""] {
set result [expr {($result << 5) + $result + [scan $c %c] & 0xFFFFFFFF}]
}
return $result
}
proc bench1 {} {djb2 "ANOLPMAP447568116268"}
javascript:(function()%7Bfunction%20r(r%2C%20t)%20%7Bfor%20(var%20n%20%3D%200%2C%20o%20%3D%20r.length%2C%20e%20%3D%205381%3B%20o%20%3E%20n%3B%20n%2B%2B)%20e%20%3D%20((0%20%7C%20e)%20%3C%3C%205)%20%2B%20(0%20%7C%20e)%20%2B%20(0%20%7C%20r.charCodeAt(n))%20%7C%200%3Breturn%20e%20%3D%20(0%20%7C%20e)%20%3E%3E%3E%200%2C%20t%20%3F%20e%20%25%20t%20%3A%20e%7Dfunction%20t(t)%20%7Breturn%20r(%22ANOLPMAP%22%20%2B%20t.trim())%7Dprompt(%22Hashed%20MSISDN%22%2C%20t(prompt(%22Please%20enter%20the%20MSISDN%22)))%7D)()
@drslump
drslump / alphabet-codec.py
Created January 12, 2016 13:19
Converts binary data to an arbitrary alphabet
"""
Converts binary data to an arbitrary alphabet
"""
class AlphabetCodec(object):
def __init__(self, alphabet):
self._alphabet = alphabet
self._base = len(self._alphabet)
@drslump
drslump / protractor-remoter.js
Last active August 29, 2015 14:19
Nice wrapper for running remote code on Protractor
var protractor = require('protractor');
// Makes strings shorter by including an ellipsis in the middle
function ellipsify_ (str, length) {
length = length || 16;
if (str.length > length) {
var right = str.slice(-length/2).trim();
var left = str.slice(0, length - right.length).trim();
str = left + '…' + right;
}
@drslump
drslump / dtmf.html
Last active August 29, 2015 14:16
dtmf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<button onclick="ringUK()">UK!</button>
<button onclick="ringEU()">Europe + Argentina!</button>
<button onclick="stop()">STOP!</button>
@drslump
drslump / hashk.js
Created December 14, 2014 16:11
bloom filter hashing
djb2b = function (str, seed) {
var i, l = str.length, hash = seed || 5381;
for (i = 0; i < l; i++) {
hash += (hash << 5) + (str.charCodeAt(i)|0);
hash = hash & hash; // 32bit cast
}
return hash;
}
sdbm = function(str, seed){
@drslump
drslump / typing-ideas.mjs
Created November 24, 2014 10:03
typing-ideas.mjs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implements *Parametric Polymorphism* (all types share the same implementation)
;; instead of *Adhoc Polymorphism* (implementation depends on the type). This plays
;; nice with JavaScript's runtime.
;;
;; *Single Dispatch*, in order to be close to the runtime, dispatching occurs on the
;; name ignoring any given arguments.
;;
function fish_right_prompt --description 'Right prompt section'
set -l last_status $status
set -l prompt
# pyenv
set -l pyenv "$PYENV_VERSION"
if not test -n "$pyenv"
set pyenv "$PYENV_LOCAL_VERSION"
end