Skip to content

Instantly share code, notes, and snippets.

View djui's full-sized avatar

Uwe Dauernheim djui

View GitHub Profile
@djui
djui / tips.md
Created September 2, 2014 09:36
Tips

Tips

This is a collection of all kinds of tips that I found to be useful over the years as most of them reflect repetative tasks but that are seldom applied. As a human... I forget. This list will soon be merge with a much longer and older list and then, I guess, I will publish it maybe as gist on Github or part of my dot-files Git repository.

OS X / Mac

@djui
djui / gtb
Last active August 29, 2015 14:07 — forked from dschuetz/gtb
#!/usr/bin/python
import hmac, struct, time, base64, hashlib # for totp generation
import re, sys, subprocess # for general stuff
from getopt import getopt, GetoptError # pretending to be easy-to-use
#
# gtb - Google(auth) + Tunnelblick
#
@djui
djui / vpn.sh
Created October 18, 2014 21:40
Takes a password, generates the TOTP token and starts the OSX VPN
#!/bin/sh
## Dependencies: $ brew install oath-toolkit
function connect {
service="$1"
password='123456'
secret=$(cat $HOME/.google_authenticator)
totp=$(oathtool --base32 --totp $secret)
@djui
djui / totp.py
Last active July 24, 2021 13:30
Simple TOTP implementation in Python as CLI
#!/usr/bin/env python
from __future__ import print_function
import base64
import hashlib
import hmac
import struct
import sys
import time
@djui
djui / keychain.py
Last active June 15, 2018 02:00
OS X Keychain implementation in Python
class Keychain():
"""Reimplementation of Keyring for OS X.
Problem with Keyring is it doesn't allow to set a label with is required
for this use case.
"""
class KeychainError(Exception):
def __init__(self, code=None, msg=None, cause=None):
self.code = code
@djui
djui / totp_mini.py
Last active August 29, 2015 14:07
Shortest TOTP I know of
#!/usr/bin/env python
import base64,hashlib,hmac,struct,time,sys
if not len(sys.argv[1:]): sys.exit('usage: totp <secret>')
digest = hmac.new(base64.b32decode(sys.argv[1]), struct.pack('>Q', int(time.time()) // 30), hashlib.sha1).digest()
offset = ord(digest[19]) & 15
print '06d' % (struct.unpack('>I', digest[offset:offset+4])[0] & 0x7fffffff % 1000000)
@djui
djui / vpn.sh
Last active August 29, 2015 14:07
#!/bin/sh -e
cmd=connect
name=$(scutil --nc list | sed -n 's/^* \+.\+\? \+.\+\? \+IPSec \+"\(.\+\?\)" \+\[IPSec\]/\1/p')
password=
secret=
token=
_usage() {
echo "Usage: $(basename $0) <command> [-n name] [-p pass] [-s secret] [-t token] [-h]"
@djui
djui / compact-vmdk.sh
Created March 12, 2015 13:47
Compacts VMDK images by converting it temporarily to a VDI image, compacting it, and then converting it back.
#!/bin/sh -e
if [ "$#" -ne 2 ] ; then
echo "Usage: compact-vmdk <VM_NAME> <IMAGE_PATH>"
echo
echo "Compacts VMDK images by converting it temporarily to a VDI image, compacting it,"
echo "and then converting it back."
echo
echo "Example:"
echo
@djui
djui / chrome_current_session.sh
Created July 7, 2015 09:20
Google Chrome Current Tabs (quick but dirty)
#!/bin/sh
PROFILE=Default
strings $HOME/Library/Application\ Support/Google/Chrome/$PROFILE/Current\ Session | sort | uniq | grep ^http
@djui
djui / Inbox-Fluid.js
Created October 6, 2015 12:26
User script for Google Inbox Fluid App to update the Badge and send notifications on new Emails
var gUnreadMails = new Set()
setInterval(checkUnread, 3000)
function checkUnread() {
updateBadge()
notify()
}
function updateBadge() {