Skip to content

Instantly share code, notes, and snippets.

View drbh's full-sized avatar
🕳️
a for AI

drbh drbh

🕳️
a for AI
  • drbh
  • state space
  • 10:58 (UTC -04:00)
View GitHub Profile
@drbh
drbh / only-even-weeks.py
Created August 5, 2020 17:04
When you only wanna update users on even weeks of the year
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 August 4, 2020 15:03
Get the numbers 0 to 50 as cardinal, ordinal, english and ints
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 July 26, 2020 01:03
Simple door state checker - truncated to ignore networking code
#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 July 26, 2020 00:58
Deep sleep enabled door state tracker that connects to WIFI and sends HTTPS request if state is changed. build target: WEMOS D1 ESP8266
// 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 July 26, 2020 00:44
Write door state updates to dynamo
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 July 26, 2020 00:41
Get human readable state of the door from dynamo table
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 April 17, 2020 19:44
WIP implementation of typed hash tree
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 April 17, 2020 18:29
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 April 3, 2020 19:28
Make circles and skew the points for jagged loops
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) => {
### 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: