Skip to content

Instantly share code, notes, and snippets.

View gvoysey's full-sized avatar
🌯

Graham Voysey gvoysey

🌯
View GitHub Profile
@gvoysey
gvoysey / SMS-IP
Last active July 28, 2016 18:23
Texts you your IP address (useful for headless linux boxes, raspberry pis, etc)
#!/bin/bash
myIP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
commandString="curl http://textbelt.com/text -d number=1111111111 -d \"message=$myIP\""
$(eval $commandString)
#call this script from /etc/rc.local with (eval "/path/to/thisscript"); get a text every time your machine reboots with the new IP.
@gvoysey
gvoysey / FakeNameGenerator.cs
Created August 31, 2015 15:19
A generator for fake names
public class FakeNameGenerator
{
private static readonly Random Random = new Random();
private static readonly List<string> _vowels = new List<string> {"a", "e", "i", "o", "u"};
private static readonly List<string> _consonants = new List<string>
{
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q",
"r", "s", "t", "v", "w", "x", "y", "z"
@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
{
@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 / 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 / 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 / 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_'
#!/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 / 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
@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: