Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
BARS = u'▁▂▃▅▆▇'
import sys
data = sys.argv[1:] or sys.stdin.read().split()
data = (x.strip() for x in data)
data = [float(x) for x in data if x]
@rogerallen
rogerallen / us_state_abbrev.py
Last active April 19, 2024 14:04
A Python Dictionary to translate US States to Two letter codes
# United States of America Python Dictionary to translate States,
# Districts & Territories to Two-Letter codes and vice versa.
#
# Canonical URL: https://gist.github.com/rogerallen/1583593
#
# Dedicated to the public domain. To the extent possible under law,
# Roger Allen has waived all copyright and related or neighboring
# rights to this code. Data originally from Wikipedia at the url:
# https://en.wikipedia.org/wiki/ISO_3166-2:US
#
@rogerallen
rogerallen / country_abbrev.py
Last active January 4, 2024 13:26
A Python Dictionary to translate Country Names to Two letter codes
# Python Dictionary to translate Countries to Two-Letter codes and vice versa.
#
# https://gist.github.com/rogerallen/1583606
#
# Dedicated to the public domain. To the extent possible under law,
# Roger Allen has waived all copyright and related or neighboring
# rights to this code. Data originally from Wikipedia at the url:
# https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
#
# Automatically Generated 2021-09-11 18:04:35 via Jupyter Notebook from
@rogerallen
rogerallen / utils.R
Created January 24, 2012 15:53
Roger's Utility Functions for R
# Roger's Utility Functions for R
#
# source("Documents/Devel/R/utils.R")
#
isMac <- function()
{
x <- Sys.info()[1]=="Darwin"
x
}
@rogerallen
rogerallen / test.clj
Created May 17, 2012 00:53
ClojureProgramming Issue 7 problem with Maze/Ariadne's Zip
;; providing this for https://github.com/clojurebook/ClojureProgramming/issues/7
;; I just copy-pasted the relevant code from
;; https://github.com/clojurebook/ClojureProgramming/blob/master/ch03-collections-repl-interactions.clj
;; there were a couple changes. see comments below...
(defn maze
"Returns a random maze carved out of walls; walls is a set of
2-item sets #{a b} where a and b are locations.
@rogerallen
rogerallen / insulter.py
Created July 23, 2012 18:52
Shakespeare Insulter in Python
#!/usr/bin/env python3
#
# http://www.pangloss.com/seidel/shake_rule.html
# Shakespeare Insult Kit
#
# Combine one word from each of the three columns below, prefaced with "Thou":
#
import random
Column_1 ="""artless bawdy beslubbering bootless churlish cockered
@rogerallen
rogerallen / insulter.clj
Created July 28, 2012 04:38
Shakespeare Insulter in Clojure
;;
;; http://www.pangloss.com/seidel/shake_rule.html
;; Shakespeare Insult Kit
;;
;; Combine one word from each of the three columns below, prefaced with "Thou":
;;
(defn split [s]
(.split s "[ \t\r\n]+"))
@rogerallen
rogerallen / diffeq.clj
Created July 30, 2012 16:18
Testing Tempo via Direct & Numerical Integration
(ns explore_overtone.diffeq)
;; we start with a differential equation:
;;
;; tempo = f(beat) or dx/dt = bps-fn(x)
;;
;; Solving the diff eq via separable eq. gives: (thanks to Tony Grabowski for his help)
;;
;; dt = dx/bps-fn(x) so t = Integrate 1/bps-fn(x) dt or Integrate spb-fn(x) dt
;; t = log(b + mx) / m - log(b) (since we set t = 0 at x = 0)
@rogerallen
rogerallen / everysong.clj
Created October 30, 2012 00:15
one chord progression
;; one chord progression to rule them all
;; The I - V - vi - IV (or C - G - Am - F)
;; iii?
;; Am F C G
;; C G Am F
;; G D Em C
;; D A Bm G
;; A E F#m D
;; E B C#m A
(ctl g :pre-amp 4.0 :distort 0.2
@rogerallen
rogerallen / sharps_n_flats.clj
Created November 16, 2012 15:37
Using TeX input mode in emacs to create & use music characters (sharp/flat) in Clojure.
(comment
Using ♯ and ♭ in clojure code and emacs.
1. To enter these glyphs in emacs, use M-x set-input-method which is
bound to C-x RET C-\. Enter "TeX" (Note, there are other options you
can use. See the docs.)
2. Turn this input mode on/off with C-\.
3. Type \sharp for ♯ and \flat for ♭. Other options include greek