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
  • 06:56 (UTC -04:00)
View GitHub Profile
@drbh
drbh / smallest-flask.py
Created October 10, 2019 18:29
A snippet i'm always looking for and cant find - just the smallest possible flask server
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run()
@drbh
drbh / inline-b64-wasm-flate-inline-loadin.js
Created October 10, 2019 15:21
Loading in wasm-flate wasm as a base64 string! < 240 KBs - not minified or optimized for size.
// https://www.npmjs.com/package/base64-arraybuffer
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
// Use a lookup table to find the index.
const lookup = new Uint8Array(256);
for (let i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
function decode(base64) {
@drbh
drbh / querying_postgres_from_python.py
Created October 1, 2019 16:59
A simple example of querying Postgres from Python assuming the DB is hosted on a AWS workspace and is password protected.
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine(
'postgresql://postgres:YOURPASSWORDHERE@*.*.*.*.us-west-2.compute.amazonaws.com:5432/postgres')
frame = pd.read_sql('SELECT * FROM my_table LIMIT 10', engine)
@drbh
drbh / wasm-flate-web-worker.js
Last active August 21, 2019 04:04
An inline web worker example of wasm-flate 🙌compress files using WASM on a separate thread!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<input type="button" value="Test" onclick="OnClickTest();" />
<script id="scriptWorker" type="javascript/worker">
@drbh
drbh / wasm-flate-fetch-node.js
Created August 21, 2019 03:24
node get wasm flate and use
const fetch = require("node-fetch");
const { TextDecoder } = require(String.raw `util`);
let wasm;
let WASM_VECTOR_LEN = 0;
var path = "https://unpkg.com/[email protected]/dist/9eae6f5a6ee0cd2a3640.module.wasm"
fetch(path)
.then(function(response) {
response.arrayBuffer()
.then(function(buffer) {
@drbh
drbh / wasm-flate-fetch-browser.js
Last active April 1, 2020 14:50
A easy way to load in wasm-flate and use it's methods
let wasm;
let WASM_VECTOR_LEN = 0;
var path = "https://unpkg.com/[email protected]/dist/9eae6f5a6ee0cd2a3640.module.wasm"
fetch(path)
.then(function(response) {
response.arrayBuffer()
.then(function(buffer) {
WebAssembly.compile(buffer)
.then(function(obj) {
WebAssembly.instantiate(obj)
@drbh
drbh / docker-compose.yml
Created March 15, 2019 19:29
start to nucypher docker network
version: '3'
services:
nucypher-alice:
command: nucypher alice run --dev --network devnet --teacher-uri 18.222.119.242:9151
environment:
- NUCYPHER_SENTRY_LOGS=0
image: nucypher:latest
container_name: nucypher-alice
ports:
@drbh
drbh / checkIsBrave.js
Created January 30, 2019 20:19
Reliably detect Brave Browser with native JS
// helper to find Brave in User Agent string
function isBraveAgent(userAgentResponse) {
var isBraveIndex = ~userAgentResponse.indexOf('Brave')
if (isBraveIndex < 0) {
return true
}
return false
}
// Function from Javarome
@drbh
drbh / websocket-lambda-handler.py
Created January 17, 2019 15:55
This script directs websocket requests and sessions with DynamoDB and another Lambda function as the game logic.
import json
import time
import sys
import os
import base64
import datetime
import hashlib
import hma
from botocore.vendored import requests
import boto3
@drbh
drbh / get_slack_id
Created January 9, 2019 19:09
click on a message with yourself in slack and enter this in the console to get your user id
alert("User Id: "+ jQuery("span.presence.active").attr("data-member-presence"))