Skip to content

Instantly share code, notes, and snippets.

View thanthese's full-sized avatar

Stephen Mann thanthese

View GitHub Profile
@thanthese
thanthese / download-mp3
Created June 21, 2017 01:53
Downloads the audio of a youtube video and converts to an .mp3 given a youtube URL.
#!/usr/bin/env bash
# Downloads the audio of a youtube video and converts to an .mp3 given a
# youtube URL.
if [ $# -eq 0 ]; then
echo "No arguments provided. Give full youtube URL."
exit 1
fi
@thanthese
thanthese / edit-gpg.sh
Last active December 29, 2015 02:18
Transparently edit an encrypted file.
#!/bin/bash
# Transparently edit an encrypted file.
#
# This system isn't intended to be perfectly secure but is rather intended to
# let me edit encrypted files on dropbox securely.
#
# Inspiration: https://gist.github.com/jakeonfire/9bf7ff1b08ed2c76fefc
set -e
@thanthese
thanthese / main.java
Created May 27, 2014 16:14
Birthday Problem, Java
package com.github.thanthese;
import java.util.HashSet;
import java.util.Set;
import java.util.Random;
public class Main {
private static final int days_in_year = 365;
private static final int trials_size = 10000;
@thanthese
thanthese / main.py
Last active August 29, 2015 14:01
Birthday Problem
import random
days_in_year = 365
trials_size = 1000
group_sizes = range(10, 30)
def is_match_in_trial(group_size):
bdays = [random.randint(1, days_in_year) for _ in range(group_size)]
return len(set(bdays)) != group_size
@thanthese
thanthese / gjava.sh
Created September 13, 2012 01:17
Search java code in git repo.
# The command
#
# gjava "foo this"
#
# Will display all lines from all java files under
# the current git repository that match the phrase
# "foo this", case insensitive.
function gjava () {
git grep -in "$1" -- "*.java"
}
@thanthese
thanthese / gist:3195027
Created July 28, 2012 22:33
convert [IO String] to IO [String]
-- I'm attempting to create a function that converts [IO String] to IO
-- [String]. I wasn't able to find one in the standard libraries, but then I'm
-- a noob.
convert :: [IO String] -> IO [String]
convert badWords = convert' badWords []
where
convert' [] good = return good
convert' bad good = bad >>= (\w -> convert' (tail bad) (w : good))
@thanthese
thanthese / gist:2582099
Created May 3, 2012 00:12
Better stats model
(let [iterations 10000.0
deck (flatten (repeat 4 (range 13)))
decks (repeat iterations deck)
first-occurs-at (for [d decks] (-> d shuffle (.indexOf 0)))]
(/ (apply + first-occurs-at)
iterations))
@thanthese
thanthese / gist:2514011
Created April 27, 2012 22:42
Pull cards until ace
(let [big 100000.0
suit (range 1 (inc 13))
deck (concat suit suit suit suit)
; fn: how many cards pulled before ace is reached?
pulled (fn [] (inc (count (take-while (partial not= 1)
(shuffle deck)))))]
; take average
(/ (apply + (repeatedly big pulled))
big))
@thanthese
thanthese / magic-square.clj
Created March 31, 2012 17:14
Magic squares in clojure
; How to use clojure to quickly create a magic square.
; First, use clojure to create some data.
; Find all combinations that sum to 15.
(def all-combos (into #{} (let [r (range 1 10)]
(for [a r
b r
c r
:when (and (not= a b)
##
# git convenience magic
# Selects the file name for the nth file from a git status method.
#
# ex: `gn 2` will return the 2nd file name
function gn() {
git status | grep : | grep -v 'commit:' | cut -d: -f2 | sed -n $1p
}