Skip to content

Instantly share code, notes, and snippets.

View bbolli's full-sized avatar

Beat Bolli bbolli

View GitHub Profile
def submit_to_transmission(self, enclosure):
"""Submit the enclosure to the Transmission RPC interface"""
conn = httplib.HTTPConnection('localhost:9091')
# the href must not be URL-encoded, or Transmission will barf
url = '/transmission/rpc?method=torrent-add&filename=' + enclosure.href
headers = {'User-Agent': 'fetcher/0.3 (+http://drbeat.li/py/)'}
self.log('Submitting "%s" to Transmission' % enclosure.href)
self.log('* Url: %s' % url, 1)
if self.dry_run:
return
@bbolli
bbolli / hotp.py
Created August 21, 2014 13:36
HOTP/TOTP one time password (RFC 4226/RFC 6238) implementation
"""HOTP/TOTP one time password (RFC 4226/RFC 6238) implementation"""
import hashlib
import hmac
import struct
def hotp(secret, counter, digits=6, alg=hashlib.sha1):
"""Calculate the HOTP value for the given secret and counter.

Keybase proof

I hereby claim:

  • I am bbolli on github.
  • I am bbolli (https://keybase.io/bbolli) on keybase.
  • I have a public key whose fingerprint is 49D5 794A EA77 F907 764F D89E 304B 93CF 506A 903A

To claim this, I am signing this object:

@bbolli
bbolli / async.cpp
Created February 18, 2015 22:45
A wrapper that runs a function with a timeout
// Needs to be compiled with -std=c++1y for optionals support
#include <chrono>
#include <cstdio>
#include <cstring>
#include <experimental/optional>
#include <future>
#include <type_traits>
@bbolli
bbolli / to_utf8.cpp
Last active November 3, 2016 10:25
An efficient and macro-less way to convert wchar_t to UTF-8
/*
* Look Ma, no macros!
*/
/**
* Append the UTF-8 encoding of @a ch to @a cont.
*/
template <class Container>
void to_utf8(Container& cont, wchar_t ch)
{
@bbolli
bbolli / win32_error_category.cpp
Created January 27, 2017 14:54
A C++11 std::error_category for Win32 and Winsock error codes
#include <system_error>
#include <windows.h>
/// Wrap the Win32 error code so we have a distinct type.
struct win32_error_code
{
explicit win32_error_code(DWORD e) noexcept : error(e) {}
DWORD error;
};
@bbolli
bbolli / Makefile
Created September 18, 2018 20:22
Makefile fragment for printing all MAKE variables
# debug support
# escape single quotes
SQ = '$(subst ','\'',$(1))'
# simple "name = value" list
print_vars = printf '%s\n' $(foreach v,$(sort ${.VARIABLES}),'$v = '$(call SQ,$($v)))
# TAB-separated list of "name origin value1 value2", where
# value1 is the unexpanded value, and value2 is the expanded value.
@bbolli
bbolli / norway.geojson
Created September 27, 2021 17:57
norway route 2021-09
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.