Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bitglue on github.
  • I am frost_remind (https://keybase.io/frost_remind) on keybase.
  • I have a public key ASBBz4XF1U2F1thPXSCwSkrYUefmYI53cDCOfBEDzEZMMAo

To claim this, I am signing this object:

@bitglue
bitglue / dht22.py
Last active January 17, 2021 04:38
"""Improved example for reading DHT22 sensors
adafruit-circuitpython-dht
<https://github.com/adafruit/Adafruit_CircuitPython_DHT/blob/master/adafruit_dht.py>
is very buggy, throwing a RuntimeError about 20% of the time when its unable to
decode the result from the sensor. The most common problem seems to be it's
unable to capture all the pulses. This is likely due to the pulseio
implementation in blinka:
https://github.com/adafruit/Adafruit_Blinka/tree/master/src/adafruit_blinka/microcontroller/bcm283x/pulseio
@bitglue
bitglue / stackprof_to_pprof.rb
Created November 5, 2020 16:38
convert a ruby stackprof file to the format required by pprof
# writes protobuf to stdout. Gzip that, and then https://github.com/google/pprof can read it.
require 'stackprof'
require 'pp'
require './profile_pb'
filename = 'profile-web-2020-11-04'
data = Marshal.load(IO.binread(filename))
class StringMap
$ mypy null.py
null.py:16: error: Argument 1 to "foo" has incompatible type "None"; expected "Bar"
Found 1 error in 1 file (checked 1 source file)
@bitglue
bitglue / xtal.py
Last active December 25, 2020 06:08
from __future__ import division
from math import pi, sqrt
r = 7.37
cs = 18.8e-15
cp = 4.15e-12
l = 6.5722e-3
l = 6.572233217077748e-3
fs = 14.318078e6
fp = 1/(2*pi*sqrt(l*(cs*cp)/(cs+cp)))
@bitglue
bitglue / 69-yubikey.rules
Last active June 15, 2020 05:16
Automatically add/remove PKCS11 provider from ssh-agent based on Yubikey presence
# Install in /etc/udev/rules.d/
# Reload with: udevadm control --reload-rules
# You might need additional model IDs here, depending on your particular Yubikey
ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="1050", ENV{ID_MODEL_ID}=="0407|0115", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/yubikey"
# See https://github.com/systemd/systemd/issues/7587
# Interestingly, this also fixes smartcard.target, which seems otherwise broken.
ACTION=="remove", SUBSYSTEM=="usb", ENV{PRODUCT}=="1050/407/*|1050/115/*", TAG+="systemd"
@bitglue
bitglue / v3-smart-home.md
Last active January 17, 2019 02:34
Alexa v3 Smart Home payload on home-assistant

Haaska implements the deprecated v2 Smart Home API, which can no longer be selected for new skills without some hackery.

Home Assistant Cloud is an alternative, but it's only available in the US.

Fortunately, the Home Assistant developers are awesome and all the logic is in Home Assistant, not hidden in the cloud. It's pretty easy to expose it via an HTTP POST interface which is easily integrated with a Lambda function.

1. Create a view to make an HTTP POST interface to Smart Home actions

from __future__ import print_function
import time
import random
from functools import wraps
def microservice(f):
@wraps(f)
def wrapper(*args, **kwargs):
# Network connections require RAM,
x = list(range(1000))

Keybase proof

I hereby claim:

  • I am bitglue on github.
  • I am indigo (https://keybase.io/indigo) on keybase.
  • I have a public key whose fingerprint is 7ECF E946 1066 A8BD FEA6 6E0E A59A 03E5 875F 1DCE

To claim this, I am signing this object:

@bitglue
bitglue / coreos.tf
Created January 15, 2015 18:23
Deploy a CoreOS cluster with Terraform
variable "cluster-size" {
description = "Number of CoreOS machines to deploy"
}
variable "region" {
description = "AWS region in which to deploy"
default = "us-east-1"
}
variable "coreos-ami" {