Skip to content

Instantly share code, notes, and snippets.

View acoster's full-sized avatar

Alex Coster acoster

View GitHub Profile

Keybase proof

I hereby claim:

  • I am acoster on github.
  • I am acoster (https://keybase.io/acoster) on keybase.
  • I have a public key ASCqvCsPTjhaXQ29gEIOzIpTIhWLXwLGbAyfGDW59Tyvywo

To claim this, I am signing this object:

@acoster
acoster / thermostat.json
Created March 25, 2023 11:35
Thermostat dashboard
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
import pytwitter
import time
import os
import sys
import schedule
from schedule import every, repeat, run_pending
twitter_conn = None
@acoster
acoster / tado.json
Last active November 16, 2022 08:14
My grafana dashboard displaying thermostat/sensor data for home.
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
@acoster
acoster / gist:7417994
Created November 11, 2013 18:34
I miscopied the tracking number for my passport's return envelope, and forgot the last digit. Luckily the Royal Mail publishes how to calculate their checksums.
import itertools
import operator
def calculate_checksum(number):
digits = [int(x) for x in number]
return 11 - (sum(itertools.imap(operator.mul, digits, [8, 6, 4, 2, 3, 5, 9, 7])) % 11)
@acoster
acoster / anagrams.cpp
Created October 7, 2013 22:07
Getting all anagrams of the english language. The filtered_dict file was generated with: curl "http://www.freebsd.org/cgi/cvsweb.cgi/src/share/dict/web2?rev=1.12;content-type=text%2Fplain" | tr "[:upper:]" "[:lower:]" | uniq > filtered_dict
#include <map>
#include <string>
#include <fstream>
#include <iostream>
int main(int argc, const char * argv[])
{
std::multimap<std::string, std::string> contents;
std::ifstream inFile("filtered_dict");
#include <iostream>
template<int _N>
struct Base
{
Base()
{
std::cout << _N << std::endl;
}
};
@acoster
acoster / knight.cpp
Created December 23, 2012 10:36
C++ solver for the Knight's Tour. Runtime on my Mac, for 8x8 board: real 0m0.530s user 0m0.529s sys 0m0.001s
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <cstring>
typedef std::pair<int, int> Position;
@acoster
acoster / bday.cpp
Created December 8, 2012 23:26
Nerdiest Birthday Message ever.
#include <string>
#include <algorithm>
#include <iostream>
#define __A "!zbei"
#define __B "zqqbI"
#define __C "\"mmjX"
#define __D "usjc!"
class App
@acoster
acoster / totp.py
Created November 20, 2012 22:45
TOTP module for Python.
#!/usr/bin/env python
"""Implementation of RFC 4226: HMAC-Based One-Time Password Algorithm (HTOP),
and RFC 6238: Time-Based One-Time Password Algorithm (TOTP).
"""
__author__ = 'acoster'
__copyright__ = 'Copyright 2012, Alexandre Coster'
import hmac