Skip to content

Instantly share code, notes, and snippets.

View hospadar's full-sized avatar

Luke Hospadaruk hospadar

View GitHub Profile
@hospadar
hospadar / counter.py
Created November 25, 2014 03:57
Python script to count keypresses. Used for winding pickups.
from __future__ import print_function
import sys, time
from collections import deque
import curses, traceback
'''
Simple counter script
Originally used for counting pickup windings for an electric violin pickup.
Of course it would work well for any pickup winding activity.
@hospadar
hospadar / generate_ngrams.py
Created February 25, 2015 20:08
DFR Tokenizer example
from __future__ import print_function
import re, sys
from nltk import ngrams, tokenize, download
from argparse import ArgumentParser
"""
#USAGE:
#This python file illustrates the techniques that Data For Research (http://dfr.jstor.org/) uses to tokenize raw text and generate n-grams
#DFR uses the NLTK 'punkt' tokenizer which needs to be downloaded separately from the nltk package.
@hospadar
hospadar / ultimate_prompt.sh
Last active March 15, 2018 18:00
Luke's Ultimate Prompt v3
#Luke's Ultimate Prompt
#displays shortened time, username, shortened absolute path, git branch status colored red if dirty, colored smiley face indicating return code of previous command
#also includes a colored mortal kombat PS2 for those long commands.
#Written by Luke Hospadaruk with lots of help from the internet
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
echo -n ' detached*'
@hospadar
hospadar / .pylintrc
Created April 15, 2015 15:52
.pylintrc
#My pylintrc for use with atom.io's linter-pylint
[MESSAGES CONTROL]
disable=W0311,W1201,W0702,W0611
@hospadar
hospadar / fake-object.clj
Last active November 21, 2016 17:44
Clojure macro to create fake java objects
;Useful macro for creating objects that can be called like java objects.
;Handy for testing clojure functions that use java objects directly.
;Allows you easily create mock objects that can be passed into clojure functions
;EX: you have a clojure function that takes a curator LeaderLatch - the only functions you actually call are start(), hasLeadership(), and close()
;It would be a major hassle to implement a leader-latch subclass just to test that the function doesn't do any work unless it hasLeadership.
;You could implement a quick fake leader latch like:
;(fake-object
; (close [this] (comment "no-op"))
(def operators [= < > <= >= not= + - * / mod and or not])
(def functions [filter select])
;not yet
;(def more_functions [select-distinct inner-join left-join group-by aggregate])
;not yet
;(def agg_func [min max sum count ])
@hospadar
hospadar / s3rmulti.py
Created February 9, 2017 20:40
Delete lots of s3 files all at once using bulk requests
#/bin/env python3
from argparse import ArgumentParser
import boto3, time, sys, random
import urllib.parse as p
batch_size = 1000
def rm_files(uri_list, total_num):
client = boto3.client('s3')
c = 0
@hospadar
hospadar / config.fish
Last active April 10, 2019 16:48
ultimate_prompt.fish
#version of my ultimate prompt for the fish shell. MUCH easier to read!
function find_git_branch
# Based on: http://stackoverflow.com/a/13003854/170413
set -l git_branch (git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [ -z "$git_branch" ]
echo -n ""
else
if [ "$git_branch" = "HEAD" ]
@hospadar
hospadar / update-freedns.sh
Created October 18, 2018 16:11
freedns dynamic dns update script
#!/bin/bash
#Handy update script for auto-updating your IP4 and IP6 dynamic DNS name if you use freedns.afriad.org.
#Probably other providers could be used as well if you modify the update URLs slightly
#uses opendns.com's magic resolver to try and figure out actual public-facing IP addresses
set -e
#To set up:
#go create an A record (for IP4) and a AAAA record (for IP6) for the same dynamic domain name
#replace the <angle bracketed sections> with the appropriate dynamic dns name and update URLs
MY_DOMAIN=<your freedns dynamic domain name>
@hospadar
hospadar / s3cat.py
Last active April 4, 2019 17:26
s3cat implementation in python
#!/usr/bin/env python3
"""
Yet-another s3cat implementation.
streams files out of s3.
Requires boto3
> pip3 install boto3
Will use whatever your default credentials are locally (i.e. whatever you set up for awscli)