This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
""" | |
faves2bibtex.py | |
Author: Scott Hawley | |
Scrapes URLs contained in tweets you (or another user) favorited ('liked') for DOI & other bibliographic info, | |
and tries to generate a set of BibTex entries to stdout. | |
Status messages go to stderr | |
Sample usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# OS-Agnostic PS5 DualSense Controller Listener | |
# Author: Scott H. Hawley | |
# Instructions: | |
# 1. Pair the DualSense controller with your computer | |
# 2. Install hidapi system binary, e.g. on Mac: brew install hidapi | |
# 3. Install Python packages: pip install hidapi pygame numpy | |
# 4. Run this script! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pysox | |
import librosa | |
import numpy as np | |
def apply_sox_effect(signal, sr, fxstr): | |
# This writes signal to a .wav file, processes it sox to another file, loads that and returns it. | |
# | |
# signal: a numpy list of numbers; the audio signal | |
# sr: the sample rate in Hz, must be an integer | |
# fxstr: a semicolon-separated string starting with the effect name followed by parameter values in order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tails output of any SLURM job that is listed in the queue. | |
# if job is pending, tailjob will wait until the output file exists | |
# usage: tailjob <job_id> | |
tailjob() { | |
local job_id=$1 | |
if [[ -n "$job_id" ]]; then | |
local stdout_file=$(scontrol show job "$job_id" | awk -F= '/StdOut=/{print $2}') | |
echo "Running tail -F $stdout_file" | |
tail -F "$stdout_file" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import soundcard as sc # Get it from https://github.com/bastibe/SoundCard | |
imWidth, imHeight = 1024, 512 # screen size | |
def draw_wave(screen, mono_audio, xs, title="oscilloscope", gain=5): | |
screen *= 0 # clear the screen | |
ys = imHeight/2*(1 - np.clip( gain * mono_audio[0:len(xs)], -1, 1)) # the y-values of the waveform | |
pts = np.array(list(zip(xs,ys))).astype(np.int) # pair up xs & ys | |
cv2.polylines(screen,[pts],False,(0,255,0)) # connect points w/ lines | |
cv2.imshow(title, screen) # show what we've got |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
<html> <head> | |
<title>WebAudio OSC Output Example - 2 Variables</title> | |
<!-- By Scott Hawley @drscotthawley. Modified from https://github.com/automata/osc-web/blob/master/web-side/app.html | |
No additional license restrictions are introduced with these modifications; the automata/osc-web site gives no license info. | |
Thus as far as this author is concerned: "unlimited license": feel free to use & modify in any way you wish! --> | |
</head> | |
<body> | |
<h2>WebAudio OSC Output Example - 2 Variables</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from einops import rearrange as _rearrange | |
class RearrangeWrapper(): | |
"wrapper to endow einops.rearrange with an 'inverse' operation" | |
def __init__(self): | |
self.shape, self.s = None, None # just in case someone tries to call inverse first | |
def __call__(self, x, s:str, **kwargs): # this 'forward' call is lightweight to preserve original usage | |
self.shape, self.s = x.shape, s | |
return _rearrange(x, s, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gamepad_Eyes_OSC: demo of using game controller for OSC input. | |
// Uses the two thumb-sticks and either the left or right bumper buttons. | |
// | |
// Peter Lager maintains the Game Control Plus library (for Processing), | |
// which provides control data for joysticks and other game controllers | |
// ...such as my Xbox 360 controller. | |
// | |
// This is a quick mash-up using Lager's Gcp_gamepad animated eyes example code, | |
// (which is in the GCP library: In Processing, go to File > Examples..., then Contributed Libraries > Game Control Plus) | |
// and Rebecca Fiebrink's Simple_Mouse_DraggedObject_2Inputs example code for Wekinator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def magic_mult(a, b): | |
""" | |
Tries to multiply two arrays/matrices in a variety of ways | |
Returns all possible working combos as a dict, with the shapes of their respective outputs | |
Author: Scott H. Hawley, @drscotthawley | |
""" | |
combos = ['a*b', 'a*b.T', 'a.T*b', 'a.T*b.T','b*a', 'b*a.T', 'b.T*a', 'b.T*a.T'] # elementwise multiplications | |
combos += [s.replace('*',' @ ') for s in combos] # matrix multiplications (I like the space here) | |
working_combos = {} | |
for s in combos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
""" | |
SLURM usage tracker Discord bot by drscotthawley & rom1504 | |
Requires external file token_channel.csv to connect to Discord | |
Syntax of that file should be: | |
token,channel | |
<DISCORD_BOT_TOKEN>,<CHANNEL_ID> |
NewerOlder