Skip to content

Instantly share code, notes, and snippets.

View tigerhawkvok's full-sized avatar

Philip Kahn tigerhawkvok

View GitHub Profile
@tigerhawkvok
tigerhawkvok / names_regex.md
Last active May 28, 2021 06:30
Names Regex

Should work with most englishy names of folks - NOT suitable for international use - but just fine for "make sure people locally give me a full name"

The Pattern

^[a-zA-Z'\u00c0-\u01ff]+[ \t]+([a-zA-Z\u00c0-\u01ff]+\.?[ \t]+)?([a-zA-Z\u00c0-\u01ff]+([\-']|[a-zA-Z\u00c0-\u01ff](\. ?)?)?)+(?<!\.|-|')[ \t]*$"

Test Success

@tigerhawkvok
tigerhawkvok / .gitconfig
Last active May 27, 2021 00:08 — forked from joechrysler/who_is_my_mummy.sh
Find the nearest parent branch of the current git branch
[alias]
parentalt = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
parent = "!vbc=$(git rev-parse --abbrev-ref HEAD) && vbc_col=$(( $(git show-branch | grep '^[^\\[]*\\*' | head -1 | cut -d* -f1 | wc -c) - 1 )) && swimming_lane_start_row=$(( $(git show-branch | grep -n \"^[\\-]*$\" | cut -d: -f1) + 1 )) && git show-branch | tail -n +$swimming_lane_start_row | grep -v \"^[^\\[]*\\[$vbc\" | grep \"^.\\{$vbc_col\\}[^ ]\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"
@tigerhawkvok
tigerhawkvok / smoothSignal.py
Last active March 17, 2020 16:13
Smooth an input signal
#!python3
import numpy as np
from typing import Union
def smooth(inputSignal:Union[list, np.ndarray], windowLength:int= 11, window:str= 'flat') -> np.ndarray:
"""
Smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
@tigerhawkvok
tigerhawkvok / listify.py
Last active March 21, 2019 16:44
Make things a list
#########
# Casting Helper
#########
def isSimpleIterable(thing) -> bool:
"""
Check if the thing is a basic iterable type
"""
return isinstance(thing, (list, set, tuple, frozenset))
@tigerhawkvok
tigerhawkvok / _quinput.py
Last active February 26, 2019 21:58
Cross-Platform Python getch, with a Y/N module for interpreter prompts.
"""
Python 2 and Python 3 input wrapper with helper Yes/No class for feedbackless boolean input
@author Philip Kahn
@date 2016
"""
class _qinput:
"""Take care of the changes in inputs between Python 2 and 3, as well as enabling a getch-like functionality"""
def __init__(self):
try:
@tigerhawkvok
tigerhawkvok / file_get_contents_curl.php
Last active September 21, 2018 22:36
cURL replacement for file_get_contents()
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
# Actual fetch
$data = curl_exec($ch);
@tigerhawkvok
tigerhawkvok / geocodeHelper.py
Created April 4, 2018 22:15
Strip down a user-provided address to its essentials
#!python3
"""
@author Philip Kahn
@license MIT
"""
def getBarebonesAddress(dirtyAddress):
"""
Will take most forms of addresses, and return an address of form
@tigerhawkvok
tigerhawkvok / baseN.py
Last active March 15, 2018 16:54
Base Converter
#!python3
def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
"""
Convert a number to an arbitrary base
Parameters
----------------
num: int, float
A numeric non-complex value
@tigerhawkvok
tigerhawkvok / noExponents.coffee
Created May 11, 2017 22:16
Remove exponents from a number in scientific notation, and return "normal" values
String::noExponents = (explicitNum = true) ->
###
# Remove scientific notation from a number
#
# After
# http://stackoverflow.com/a/18719988/1877527
###
data = @.split /[eE]/
if data.length is 1
return data[0]
@tigerhawkvok
tigerhawkvok / urlMatch.coffee
Last active March 29, 2017 03:14
Basic Web URL validation
###
# This was created as part of an attempt to handle well-formatted but regular URL input from the client
#
# In my specific use case, it was just fetching license URLs so it frankly just needed to work for
# Creative Commons, GPL, MIT, and other common license URLS
#
# Longer, more robust patterns like
# https://gist.github.com/gruber/8891611
#
# Were proving fussy when integrating a pattern with <paper-input>