This file contains hidden or 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 radius (if (empty? *command-line-args*) | |
12 | |
(Integer/parseInt (first *command-line-args*)))) | |
(defn stream [radius] | |
(let [full-range (range (- radius) | |
(inc radius))] | |
(for [x full-range | |
y full-range | |
z full-range] |
This file contains hidden or 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
## | |
# 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 | |
} |
This file contains hidden or 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
; 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) |
This file contains hidden or 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
(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)) |
This file contains hidden or 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
(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)) |
This file contains hidden or 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
-- 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)) |
This file contains hidden or 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
# 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" | |
} |
This file contains hidden or 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 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 |
This file contains hidden or 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
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; |
This file contains hidden or 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
#!/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 |
OlderNewer