Skip to content

Instantly share code, notes, and snippets.

@ZJONSSON
ZJONSSON / lambda.js
Created January 22, 2019 16:54
CircleCI coverage lambda
const Promise = require('bluebird');
const request = require('request');
const requestAsync = Promise.promisify(request);
const USER = process.env.GITHUB_USER;
exports.handler = async (event, context) => {
try {
if (!USER) throw new Error('GITHUB_USER env missing');
const module = event.pathParameters.module;
@ZJONSSON
ZJONSSON / Dockerfile
Created September 18, 2017 17:51
scipy-notebook with rasterio
FROM jupyter/scipy-notebook
USER root
RUN apt-get update
RUN apt-get -y install software-properties-common
RUN apt-get -y install apt-utils
RUN conda install gdal -y
USER jovyan
RUN pip install rasterio

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@ZJONSSON
ZJONSSON / app.js
Last active August 29, 2015 14:04
Happy Birthday
function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {
@ZJONSSON
ZJONSSON / README.md
Last active August 29, 2015 14:04
Optimal denominations

This small script uses combinatory analysis to figure out the optimal denominations for given number of possible coins to minimize the coins required to produce any amount between 1 cent and 1 dollar. The candidate set of denominations is reduced to keep the combinatory possibilities within reason.

@ZJONSSON
ZJONSSON / arb.js
Last active May 2, 2024 08:49
Bitcoin Arbitrage (extension)
// Get all k-combinations from array
function combinations(arr, k){
if (k==1) return arr;
var ret = [];
arr.forEach(function(d,i) {
combinations(arr.slice(i+1, arr.length), k-1)
.forEach(function(sub) {
var next = [].concat(sub);
next.unshift(d);
ret.push( next );
@ZJONSSON
ZJONSSON / arb.js
Last active January 1, 2016 11:29
Bitcoin Arbitrage - Priceonomics
// Get all possible states for a k length array
function states(k) {
if (k==1) return [0,1];
var ret = [];
states(k-1).forEach(function(d) {
ret.push([0].concat(d));
ret.push([1].concat(d));
});
return ret;
}
@ZJONSSON
ZJONSSON / index.html
Last active January 22, 2020 00:11
New York Traffic - Live
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<a style="font-size:10px" href="http://nyctmc.org/">Source: nyctmc.org</a><br>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var cams = [252,263,644,494,200,489,488,486,485,484,487,261,251,102,491,258,497,400,203,430,431,290,429,428,432,305,466,299,465,446,448,304,401,447,440,439,444,443,441,355,354,352,350,349,468,469,455,424,425,427,281,551,335,116,434,550,105,106,285,286,438,337,194,348,548,538,547,530,524,536,523,527,526,517,532,535,539,529,528,521,531,537,525,519,533,318,325,324,339,340,445,464,496,341,178,143,166,442,643,642,641,419,329,330,420,421,426,202,201,635,481,127,108,269,268,266,609,509,508,505,504,503,506,502,510,279,280,140,163,603,604,605,606,611,459,457,458,453,500,495,175,173,188,247,615,616,450,483,482,303,302,294,182,157,129,264,570,571,572,555,560,562,564,565,566,563,567,556,569,568,558,573,561,557,191,296,297,467,470,475,111,184,386,397,399,273,613,614,612,122,187,289,186,473,309,492,316,3
@ZJONSSON
ZJONSSON / index.html
Last active December 18, 2015 22:38
Nearest Citibike
<!DOCTYPE HTML>
<style>
body {font-family: Verdana, Geneva, sans-serif;font-size:14px;}
th {font-weight:bold;text-align:left;}
td,th {padding-left:5px;}
</style>
<body>
<script>
var data,pos,limit=10;
@ZJONSSON
ZJONSSON / adaptor.js
Last active December 18, 2015 04:39
Minimalistic Promises A+ framework (without setTimeout/nextTick. 2 of 231 test fail)
var promin = require("promin");
module.exports.adaptor = {
fulfilled: function(value) { return promin().set(true, [value]); },
rejected: function(reason) { return promin().set(false, [reason]); },
pending: function() {
var p = promin();
return {
promise: p,
fulfill: function(value) {