Skip to content

Instantly share code, notes, and snippets.

View thusoy's full-sized avatar

Tarjei Husøy thusoy

View GitHub Profile
@thusoy
thusoy / debug_logger.py
Created December 4, 2013 21:36
A short example of how to log output from a NXT device using python. and jaraco.nxt.
def log():
print("Establishing connection...")
conn = Connection(3, timeout=5)
print('Logging output...')
while True:
print('Listening for output...')
try:
resp = conn.receive()
except struct.error:
print("Timed out")
@thusoy
thusoy / netst
Created February 3, 2015 14:37
Windows equivalent of netstat -tulpn
#!/bin/bash
# Normally windows doesn't give out the process name when you run netstat -ano, thus making it
# hard to figure out what process is bound to the different ports. This script extracts the PID
# from the netstat output, and fetches the corresponding binary name from the tasklist, and
# merges the two together. Needs a MinGW environment like Git Bash and python to work.
{ tasklist | tail -n +5; echo ===; netstat -ano | grep LIST; } | python -c "
import sys
pad = [0, 21, 9, 0, 5, 8, 0]
@thusoy
thusoy / index.html
Created February 3, 2015 14:50
Simple site to get lat/lon coordinates of a point from OSM with OpenCycleMap tiles.
<!doctype html>
<html>
<head>
<title>Hike map</title>
<style>
html, body, #map {
height: 100%;
}
</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
@thusoy
thusoy / check_transit_encryption.py
Last active August 29, 2015 14:22
Check IMAP inbox for mail transit encryption
#!/usr/bin/env python
"""
Count percentage of mail in IMAP inbox delivered over TLS, based on
presence of ESMTPS header.
"""
from collections import defaultdict
from contextlib import contextmanager
from email.parser import HeaderParser
from itertools import chain, islice
@thusoy
thusoy / jottacloud-duplicity-backend.py
Created September 4, 2015 16:47
Jottacloud backend for duplicity using jottalib
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf-8 -*-
#
# Copyright 2014 Håvard Gulldahl
#
# in part based on dpbxbackend.py:
# Copyright 2013 jno <jno@pisem.net>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
@thusoy
thusoy / gconcats-to-mutt.py
Last active November 26, 2022 19:32
Convert your Google contacts to mutt format
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This script is designed to sync mutt aliases with Google contacts
from __future__ import unicode_literals
import sys
import datetime
import atom
@thusoy
thusoy / pip-install-with-hash.sh
Created April 10, 2016 18:44
Run pip install and get hash in one step
#!/bin/sh
# Install and get hash in one step
#
# Downloads the packages to a temporary directory, gets the hash of the
# package and all dependencies, extracts the package names and prints
# a requirements.txt compatible string with the hash
set -e
@thusoy
thusoy / pinboard_from_pocket.py
Created December 25, 2016 10:10
Import to Pinboard from Pocket while preserving read status and multi-word tags.
import sys
import time
import os
import re
import requests
def main():
to_read = 'yes'
@thusoy
thusoy / uber_trips_to_csv.py
Created December 18, 2017 19:02
Scrape Uber trips and output as csv.
#!/usr/bin/env python
import argparse
import csv
import os
import time
import sys
import traceback
import datetime
from collections import OrderedDict
#!/bin/bash
# Make this executable and name it .git/hooks/pre-commit to have commits
# randomly rejected with a prompt to rethink it. The odds are higher for
# longer commits
set -eu
# How many lines a commit must have before it's considered long and should
# have the highest odds of getting an extra prompt