Skip to content

Instantly share code, notes, and snippets.

View gvoysey's full-sized avatar
🌯

Graham Voysey gvoysey

🌯
View GitHub Profile
@gvoysey
gvoysey / lowpass.py
Created July 1, 2021 01:44
lowpass filter
from scipy.signal import butter, filtfilt, welch
from scipy.fftpack import fft
import numpy as np
import matplotlib.pyplot as plt
def lowpass(data, fs, cutoff=25, order=5):
"""
A lowpass, zero-phase butterworth filter
:param data: array-like; the data to be filtered.
Russian Tea HOWTO
Dániel Nagy <nagydani@fazekas.hu>
v1.0, April 1, 2002
Caffeine is essential for keeping the brain active during nightly
hacking sessions. There are, however, many ways to satisfy a hacker's
need for caffeine. Drinking Canned Capitalism (Coke) contradicts the
very principles of the open source movement, for it is a closed
source product, manufactured by a huge, evil corporation. This sweet
brown fizzy water is unhealthy and does not leave any space for cre
@gvoysey
gvoysey / flattener.py
Last active November 30, 2022 22:36
recursively flatten nested iterables without fucking up stringlikes.
from collections.abc import Iterable
def should_flatten(x):
return isinstance(x, Iterable) and not isinstance(x, (str, bytes))
def flatten(x, should_flatten=should_flatten):
for y in x:
if should_flatten(y):
yield from flatten(y, should_flatten=should_flatten)
else:
@gvoysey
gvoysey / pycli
Created February 1, 2019 16:38 — forked from energizah/pycli
#!/usr/bin/env python3
import argparse
import os
import pathlib
import shutil
import subprocess
import sys
import types
#!/usr/bin/python3
from collections import defaultdict
def words(words_file):
"""Return one word at a time from a potentially very large list of words."""
with open(words_file, 'r') as f:
for line in f:
# give back one word at a time, with no whitespace, and converted to
# lowercase.
yield line.casefold().strip()
@gvoysey
gvoysey / matlab_sanitizer.py
Last active November 16, 2017 22:55
munges a string so that it is a valid matlab variable name
import re
def known_bad(x):
"""provide string substitutions for common invalid tokens, or remove them if not found."""
return {' ': '_',
'(': '_lp_',
')': '_rp_',
'-': '_minus_',
'/': '_div_',
';': '_sc_'
@gvoysey
gvoysey / keybase.md
Last active February 8, 2017 21:37
keybase.md

Keybase proof

I hereby claim:

  • I am gvoysey on github.
  • I am gvoysey (https://keybase.io/gvoysey) on keybase.
  • I have a public key ASCiKnCcR0KDp_QviGppyRFCap15HpQX1NkYIn1eLiPwbAo

To claim this, I am signing this object:

@gvoysey
gvoysey / JsonObjectExtensions.cs
Last active October 10, 2015 23:50
serialization and hashing extensions.
public static class JsonExtensions
{
public static T AsDeserialized<T>(this string instance)
{
T item;
try
{
item = JsonConvert.DeserializeObject<T>(instance, JsonSerializerSettings);
}
@gvoysey
gvoysey / QueuedWriter.cs
Created October 8, 2015 20:44
threaded writer for large files
public class QueuedWriter
{
private byte[] Pw
{
get { return new UnicodeEncoding().GetBytes(UserID.GetSHA1Hash()).Take(16).ToArray(); }
}
public int UserID { get; set; }
private static volatile object _lockObject = new object();
@gvoysey
gvoysey / hasher.cs
Created September 12, 2015 15:24
c# hashing class as object extension.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text;
//ref http://alexmg.com/compute-any-hash-for-any-object-in-c/
namespace Foo
{