Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / bloom.py
Created September 28, 2017 16:06
A basic bloom filter implementation
#!/usr/bin/env python3
''' A basic bloom filter implementation'''
from bitarray import bitarray
from hashlib import sha256
import math
def h_i(i, m, s):
'''
Our "uniformly distributed" hash function: h_i(s) = sha256(s + i) % m
### Keybase proof
I hereby claim:
* I am dannycroft on github.
* I am dannycroft (https://keybase.io/dannycroft) on keybase.
* I have a public key ASCOJTYfcKRcaND9PnQqyF-0XeDeh7q8zaU5CgHPWeqYhAo
To claim this, I am signing this object:
@dannycroft
dannycroft / templates.json
Created December 1, 2017 14:52
Stack Templates
[{
"type": "container",
"title": "Registry",
"description": "Docker image registry",
"categories": ["docker"],
"platform": "linux",
"logo": "https://cloudinovasi.id/assets/img/logos/registry.png",
"image": "registry:latest",
"ports": [
"5000/tcp"
@dannycroft
dannycroft / ec2-instances.sh
Created December 15, 2017 12:42
Get a list of instance with id, name and type
aws --output table ec2 describe-instances --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value,InstanceId,InstanceType]'
@dannycroft
dannycroft / fancy-logs.js
Created January 7, 2018 10:46
Jazz hands for your console logs
const log = new Proxy({}, {
get: (_, color) => (...args) => {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
});
// example
log.tomato('I am tomato');
log.chocolate('I am chocolate');
log.cornflowerblue('I am cornflowerblue');
@dannycroft
dannycroft / configure.sh
Created February 1, 2018 13:55
Docker and Kubernetes setup
#!/bin/sh
sudo apt-get update \
&& sudo apt-get install -qy docker.io
sudo apt-get update \
&& sudo apt-get install -y apt-transport-https \
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
@dannycroft
dannycroft / getUsers.js
Last active June 1, 2018 09:47
Simple challenge to collect and parse users
/* -----------------------------------------------------------------------------
Complete the following tasks using only browser based APIs. Update
the supplied "getUsers()" function to achieve the following:
- Make a request to the API_URL (see below)
- Return a Promise
- Parse each of the returned results to match the example below:
[
@dannycroft
dannycroft / RequestQueue.js
Created August 15, 2018 08:56
RequestQueue to ensure that only a single request is executing at a time.
import EventEmitter from 'events';
import onFinished from 'on-finished';
/*
* RequestQueue to ensure that only a single request is executing at a time.
*
* This middleware intercepts requests as they come in by delaying executing of
* next() until previous requests finish processing. This complements external
* server configuration via haproxy or similar that restricts concurrent
* requests. This per-process queue allows an application level guarantee of
@dannycroft
dannycroft / pi-stats.py
Last active October 1, 2019 12:40
PI Stats
import os
# Return CPU temperature as a character string
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
# Return RAM information (unit=kb) in a list
# Index 0: total RAM
# Index 1: used RAM
/* ------------------------------- */
/* common/errorHandler.js */
/* ------------------------------- */
const asyncUtil = fn =>
function asyncUtilWrap(...args) {
const fnReturn = fn(...args)
const next = args[args.length-1]
return Promise.resolve(fnReturn).catch(next)
}