Skip to content

Instantly share code, notes, and snippets.

View endolith's full-sized avatar
😑

endolith

😑
View GitHub Profile
@endolith
endolith / consonance.py
Last active January 27, 2023 16:47
Functions for just intonation, consonance, roughness, dissonance, etc. in Python
"""
Collection of functions related to musical consonance, Just intonation, etc.
"""
from fractions import Fraction
from math import log
from functools import reduce
def product(*iterable):
@endolith
endolith / notes.txt
Last active March 15, 2017 04:08
pycalcy - unit calculator for Launchy
Needs to handle all these situations. Make them happen and get a useful result from each
errors from single-shot command is different from interactive session
more complex than just returning stripped version:
'conformability error: g = 0.001 kg and m = 1 m'
'reciprocal conversion: 1 / s = 1 Hz and 1 / s = (1 / 1) Hz'
Can't just do this for multiple lines or you will get
'g = 0.0022046226 lb: g = (1 / 453.59237) lb and'
* "Successful completion"
@endolith
endolith / .units.dat
Last active August 30, 2015 10:35
Custom unit definitions for GNU Units
# Custom unit definitions for GNU Units
# http://www.gnu.org/software/units/
# The bel was defined by engineers of Bell Laboratories to describe the
# reduction in audio level over a length of one mile. It was originally
# called the transmission unit (TU) but was renamed around 1923 to honor
# Alexander Graham Bell. The bel proved inconveniently large so the decibel
# has become more common. It is used in various to contexts to report a
# signal's power relative to some reference level.
@endolith
endolith / browser_utils.py
Created June 13, 2009 21:33
Python browser shortcuts
#!/usr/bin/env python
"""Some utilities for working with the web browser
function call_browser(url) opens url in the user's default browser
function browser_render(html) sends HTML to the user's default browser for display
"""
import tempfile
@endolith
endolith / freq.m
Last active September 16, 2020 18:15
Count zero crossings to determine frequency
function [frequency, period, crossings, seconds, samples]=freq(wavefile, siz)
% FREQ Measures frequency of mono .WAV files by counting zero crossings
%
% [frequency, period, crossings, seconds, samples]=freq(wavefile, siz, fmt24bit)
%
% frequency : in hertz
% period : in seconds
% crossings : the total number of zero crossings
% seconds : total amount of time between first and last zero crossing
@endolith
endolith / currency.dat
Created June 19, 2009 05:09
Proposed changes to GNU Units database
#
# Money
#
# Note that US$ is the primitive unit so other currencies are
# generally given in US$.
#
$ dollar
mark germanymark
bolivar venezuelabolivar
@endolith
endolith / README.md
Last active November 27, 2023 16:06
PonyProg2000: Flip bit order in a binary file

It's been a long time since I used this, and I don't remember its purpose. I think it's for writing a binary file to an EEPROM, when the chip reading that EEPROM expects the bits in reversed order.

flip_bits.py can be used on a file directly, as well, though in the context of the script it just operates on temporary files:

python flip_bits.py infile outfile

I'm sure this could be done with a very simple C command line tool instead. But hey, it works.

@endolith
endolith / A_weighting.py
Last active March 15, 2024 07:12
A-weighting audio files in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Translated from a MATLAB script (which also includes C-weighting, octave
and one-third-octave digital filters).
Author: Christophe Couvreur, Faculte Polytechnique de Mons (Belgium)
couvreur@thor.fpms.ac.be
Last modification: Aug. 20, 1997, 10:00am.
BSD license
@endolith
endolith / stripnewlines.py
Last active November 19, 2019 22:11
Convert newlines in filenames to spaces
#!/usr/bin/env python
import os
# I often find myself opening a lot of PDFs, copying and pasting the title of
# the paper, and renaming the file. Often these names have newlines in them,
# though, so this script renames them with spaces instead of newlines.
for name in os.listdir(os.curdir):
if '\n' in name:
new_name = name.replace('\n', ' ')
@endolith
endolith / constants.dat
Created July 20, 2009 01:53
GraphCalc unit definitions
*GROUP*
Math
pi
3.141592653589793238462
*GROUP*
Physics
c (m/s)
299792458
Boltzman's constant (J/K)
1.380658*10^-23