Skip to content

Instantly share code, notes, and snippets.

View hwms's full-sized avatar

hwms hwms

  • hwms
View GitHub Profile
from pyparsing import *
# By default, PyParsing treats \n as whitespace and ignores it
# In our grammer, \n is significant, so tell PyParsing not to ignore it
ParserElement.setDefaultWhitespaceChars(" \t")
def parse(input_string):
def convert_prop_to_dict(tokens):
"""Convert a list of field property tokens to a dict"""
prop_dict = {}
@hwms
hwms / curry.py
Last active August 29, 2015 14:14 — forked from JulienPalard/curry.py
#!/usr/bin/env python
def curry(func):
"""
Decorator to curry a function, typical usage:
>>> @curry
... def foo(a, b, c):
... return a + b + c
@hwms
hwms / fncache.py
Last active August 29, 2015 14:14 — forked from kwarrick/fncache.py
#!/usr/bin/env python
__author__ = 'Kevin Warrick'
__email__ = 'kwarrick@uga.edu'
import cPickle
from functools import wraps
def redis_lru(capacity=5000, slice=slice(None)):
"""
Simple Redis-based LRU cache decorator *.
@hwms
hwms / bluetooth.py
Last active August 29, 2015 14:17 — forked from tito/bluetooth.py
'''
Bluetooth/Pyjnius example
=========================
This was used to send some bytes to an arduino via bluetooth.
The app must have BLUETOOTH and BLUETOOTH_ADMIN permissions (well, i didn't
tested without BLUETOOTH_ADMIN, maybe it works.)
Connect your device to your phone, via the bluetooth menu. After the
pairing is done, you'll be able to use it in the app.
@hwms
hwms / gist:1ea10c16683e33da0761
Created July 9, 2015 11:00
Find unused class and def definitions in python code
#!/bin/bash
for F in "$@"; do
DEFS=`grep -E '^ *def|^ *class' ${F} | sed -e 's/^ *//g' | cut -d ' ' -f 2 | cut -d '(' -f 1 | cut -d ':' -f 1 | sort | sed ':a;N;$!ba;s/\n/\n/g' | uniq`
#echo $DEFS
for D in $DEFS; do
COUNT=`grep -rn $D | wc -l`
#echo $D $COUNT
if [ $COUNT -eq 1 ]; then
grep -rn $D
fi
"""http://www.peterbe.com/plog/uniqifiers-benchmark for py3 + orderedset""
from __future__ import print_function
from random import shuffle, randint
import re
try:
from sets import Set
except ImportError:
Set = set
#!/usr/bin/env bash
#
# Script is a mini version of https://github.com/jules-ch/Ubuntu20-Setup-XPS13/blob/master/setup.sh
set -ex
# Get the Ubuntu version installed
DISTRO_VER=$(lsb_release -r -s)
LOGIN_USER=$(logname)