Skip to content

Instantly share code, notes, and snippets.

View tigerhawkvok's full-sized avatar

Philip Kahn tigerhawkvok

View GitHub Profile
@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 / poetry-convert.py
Last active April 19, 2024 23:31
Convert a requirements.txt file to a Poetry project
#!python3
"""
Convert a requirements.txt file to a Poetry project.
Just place in the root of your working directory and run!
"""
sourceFile = "./requirements.txt"
import re
import os
@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 / 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>
@tigerhawkvok
tigerhawkvok / pandoc_convert.command
Created November 12, 2016 19:19
Convert all HTML files into Markdown files in a given directory
#!/bin/bash
find . -type f -iregex .*\.html$ | while read line
do
printf 'Converting >>>%s<<<\n' "$line"
P_MD=${line%".html"}.markdown
pandoc --ignore-args -r html -w markdown < "${line}" | awk 'NR > 130' | sed '/<div class="site-info">/,$d' > "${P_MD}"
done
@tigerhawkvok
tigerhawkvok / StringUnescaper.coffee
Last active March 4, 2016 21:04
Unescape even fairly mutilated escaped string in Javascript
String::unescape = (strict = false) ->
###
# Take escaped text, and return the unescaped version
#
# @param string str | String to be used
# @param bool strict | Stict mode will remove all HTML
#
# Test it here:
# https://jsfiddle.net/tigerhawkvok/t9pn1dn5/
#