Skip to content

Instantly share code, notes, and snippets.

@kylelemons
kylelemons / minimax_games.go
Created October 27, 2017 04:00
minimax_games implements the Minimax Candorcet with the (non-candorcet) pairwise opposition model.
// minimax_games implements the Minimax Candorcet with the (non-candorcet) pairwise opposition model.
//
// See: https://en.wikipedia.org/wiki/Minimax_Condorcet
package main
import (
"fmt"
"os"
"sort"
"text/tabwriter"
@kylelemons
kylelemons / routes.java
Created September 6, 2017 20:30
VpnService.Builder code for excluding local ranges
// IPv4
//
// Excluded ranges:
// 10.0.0.0/8
// 172.16.0.0/12
// 192.168.0.0/16
// 100.64.0.0/10
// 224.0.0.0/4
// 240.0.0.0/4
builder.addRoute("0.0.0.0", 5)
@kylelemons
kylelemons / salclient.go
Created July 25, 2017 23:08
Very quick example of an HTTP client that connects to a server and posts URLencoded key-value pairs
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"
"net/url"
"os"
@kylelemons
kylelemons / getproducts_on.py
Last active July 21, 2017 18:02
Get the products of a list excluding the current element
#!/usr/bin/python3
def getProducts(values):
""" Return an array where each index is the product of all other values, runs in O(N) time """
left = []
leftProduct = 1
right = []
rightProduct = 1
for i in range(len(values)):
left.append(leftProduct)
$ /usr/bin/python3.4
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> letters = 'abcdefghijklmnopqrstuvwxyz'
>>> shift = lambda s, d: s[d:]+s[:d]
>>> trans = lambda d: shift(letters.lower(), d)+shift(letters.upper(), d)
>>> encrypt = lambda s, d: s.translate(str.maketrans(trans(0), trans(d)))
>>> decrypt = lambda s, d: encrypt(s, -d)
>>> encrypt('You cracked the code!', 14)
kyle@vms:/$ ls ??????
13Tbdh 35ZSQF 5dJX5p 7M2c5l 9KnUrh aGDiMc b5fj7V C1EcWM cr3WvL DE_YT9 eJxq5F fp6Bjb GINwCO hcfd_G i3KmrS IqyBV9 JvPOHG LGyykg m8hW6R N1FJ3_ O9muzU paaGyO q58i0G QXxd12 rZmafX sWzMje Ts4qKq uK0rn0 VmmBef WLRUb0 XFgpHO Yc1XPW YstT48 zpc0st
15fZ5C 3_6FKJ 5EByEW 7oMtwI 9Mk_38 AhrQKy B6LaRU c31UgP cr88zM DHE0zI EL8T1X fPj0jS gmCcvf HE4wqh i6uRVa iSFDXB jwbxWe lkoJC7 mAtmSe N3qsqv oAEA5I PCipQM Q5z9cg QZ39LR s4JFp8 T5oH3_ TsKWOt UM8zRo VNMA1V wMeDej xfrZoV YCbBXC YT8lMb zps2th
1B0vgN 36no1t 5gzhQE 7XiGqa 9MRlGy AHucEO b6xF1Z C3QbmL cRAITG DhOSox eLCjXc ftdh5H _GMMXK HhqpL_ i9iBiu IW6GUw jwhcmB lKQftv MduUfp n9159P OAYO1s PDJX1w q9mC8_ qz5szd S7lpgO tbI847 tUNKyU uMGEl1 vQa0RO Wmj38N Xg_FkD yd1iTX y_URrE ZrFZch
1flb1x 382xdp 5llPhq 84Do7G 9o2mVu AIdwbP B7ci7u c5GqWd cS5w_e DI_L2o elwrcm F_uAPk gMRh1A HjwlvE I9kUDL IWI_om jwPkXQ llhaqt mFqN9J N9V4q9 oBIGxg PdtDAi QB8Cqj QZ6N6
package b62
import (
"math"
"testing"
)
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func base62EncodeB(num int) []byte {
@kylelemons
kylelemons / frontend-service.yaml
Last active August 29, 2015 14:18
Frontend service description for Kubernetes
id: frontend
kind: Service
apiVersion: v1beta1
selector:
app: frontend
labels:
app: frontend
containerPort: 80
port: 80
publicIPs:
@kylelemons
kylelemons / ghost-service.yaml
Last active August 29, 2015 14:18
Kubernetes service descriptions for Ghost
id: ghost
kind: Service
apiVersion: v1beta1
selector:
app: ghost
labels:
app: ghost
containerPort: 2368
port: 2368
@kylelemons
kylelemons / frontend-controller.yaml
Created April 5, 2015 00:27
Frontend ReplicationController config
id: frontend
kind: ReplicationController
apiVersion: v1beta1
labels:
app: frontend
desiredState:
replicas: 1
replicaSelector:
app: frontend
podTemplate: