Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Peace, Love & WASM

drbh drbh

🚀
Peace, Love & WASM
View GitHub Profile
@drbh
drbh / only-even-weeks.py
Created Aug 5, 2020
When you only wanna update users on even weeks of the year
View only-even-weeks.py
import datetime
# get the week of the year
week_number = datetime.datetime.now().isocalendar()[1]
print(f"Its the {week_number} week of the year")
# this is True every other week
should_update_users = week_number % 2 == 0
if should_update_users:
@drbh
drbh / 0-50-mappings.py
Created Aug 4, 2020
Get the numbers 0 to 50 as cardinal, ordinal, english and ints
View 0-50-mappings.py
import string
# mostly copied form here
# https://www.mathsisfun.com/numbers/cardinal-ordinal-chart.html
nth = {
1: "First",
2: "Second",
3: "Third",
4: "Fourth",
5: "Fifth",
@drbh
drbh / door-state-tracker-naive.cpp
Created Jul 26, 2020
Simple door state checker - truncated to ignore networking code
View door-state-tracker-naive.cpp
#include <ESP8266WiFi.h>
#include <EEPROM.h>
// networking and request related
int inputVal = 0;
int addr = 0;
int lastValue;
// networking and request related
void sendMessageToLambda(int currentState) {
// networking and request related
@drbh
drbh / door-state-tracker.cpp
Created Jul 26, 2020
Deep sleep enabled door state tracker that connects to WIFI and sends HTTPS request if state is changed. build target: WEMOS D1 ESP8266
View door-state-tracker.cpp
// memory
#include <EEPROM.h>
// networking
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
@drbh
drbh / write-door-state.py
Created Jul 26, 2020
Write door state updates to dynamo
View write-door-state.py
import json
import boto3
import datetime
import dateutil.tz
eastern = dateutil.tz.gettz('US/Eastern')
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("<DOOR-STATE-TABLE-NAME>")
def lambda_handler(event, context):
@drbh
drbh / read-door-state.py
Created Jul 26, 2020
Get human readable state of the door from dynamo table
View read-door-state.py
import json
import boto3
import decimal
import datetime
import calendar
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
@drbh
drbh / typed-hash-tree-construction_v2.ipynb
Last active Apr 17, 2020
WIP implementation of typed hash tree
View typed-hash-tree-construction_v2.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drbh
drbh / typed-hash-tree-construction.ipynb
Created Apr 17, 2020
typed-hash-tree-construction.ipynb
View typed-hash-tree-construction.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drbh
drbh / jagged-loops.js
Last active Apr 3, 2020
Make circles and skew the points for jagged loops
View jagged-loops.js
const range = (start, end, length = end - start) =>
Array.from({ length }, (_, i) => start + i);
const randomNumber = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const points_in_circle = (r, n) => {
View gist:30ef6387328890ad11338248c1bfaa72
### Keybase proof
I hereby claim:
* I am drbh on github.
* I am drbh (https://keybase.io/drbh) on keybase.
* I have a public key ASBjal2m3iJOdayg_el6CbiP0F7wTd4I23tUu64PeAkcGwo
To claim this, I am signing this object:
You can’t perform that action at this time.