Skip to content

Instantly share code, notes, and snippets.

View micmarsh's full-sized avatar

Michael Marsh micmarsh

View GitHub Profile
@micmarsh
micmarsh / flip.clj
Last active May 12, 2022 17:16
Flip the arguments of a function, Clojure style
(defn flip [function]
(fn
([] (function))
([x] (function x))
([x y] (function y x))
([x y z] (function z y x))
([a b c d] (function d c b a))
([a b c d & rest]
(->> rest
(concat [a b c d])
@micmarsh
micmarsh / seeded_random.clj
Created October 7, 2016 18:48
Utilities that I always end up implementing in an exploratory phase, before deciding that test.check is better
(defn rand-int'
([seed] (rand-int' seed Integer/MAX_VALUE))
([seed upper] (rand-int' seed 0 upper))
([seed upper min]
(-> (hash seed)
(Math/abs)
(mod (- upper min))
(+ min)
(dec))))
@micmarsh
micmarsh / compose.coffee
Last active December 31, 2015 01:49
Compose Promises and Synchronous Functions
# use lodash/underscore, this could probably actually be a mixin for those
compose = (fns) ->
_.reduceRight fns, (composed, currentFn) ->
_.compose (valueOrPromise) ->
vop = valueOrPromise
if Boolean vop and vop.then
vop.then (value) ->
currentFn value
else
currentFn vop
@micmarsh
micmarsh / queue.clj
Last active December 30, 2015 22:39
Persistent Queue In Clojure
; Clojure actually has a queue type, but it's not easily accesible. Here's a function to help with that
(defn queue
([] clojure.lang.PersistentQueue/EMPTY)
([& elements]
(into (queue) elements)))
#!/bin/bash
# essentials
sudo apt-get install git curl emacs24 vim cowsay
# sublime
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text
DROP TABLE test_notes;
DROP TABLE billing_discount_notes;
drop table billing_notes;
DROP TABLE billing_discounts;
CREATE TABLE billing_notes (
id SERIAL PRIMARY KEY,
note text,
created TIMESTAMP WITHOUT TIME ZONE,
updated TIMESTAMP WITHOUT TIME ZONE

Keybase proof

I hereby claim:

  • I am micmarsh on github.
  • I am micmarsh (https://keybase.io/micmarsh) on keybase.
  • I have a public key whose fingerprint is 960F 064A BB01 F97C 1A15 FCE6 3B81 08D4 B735 857C

To claim this, I am signing this object:

@micmarsh
micmarsh / organize.hs
Created December 15, 2014 00:35
Journal Mode Organizer
import System.Directory as D
import Data.List (sort, cycle)
import Data.Set (fromList, member, Set)
import Data.List.Split (chunksOf)
import Data.Time.Calendar as C
import Control.Monad (sequence_)
-- Date parsing related functions
slice :: Int -> Int -> [a] -> [a]
Verifying myself: My Bitcoin username is +micmarsh. https://onename.io/micmarsh
@micmarsh
micmarsh / Cleanup.hs
Last active August 29, 2015 14:03
Clean Up Your Downloads Folder
import System.Directory
import System.IO (hFlush, stdout)
import Control.Exception (try, SomeException)
-- "Downloads" folders tend to get unwieldy.
-- This will force a decision on every downloaded file, with
-- a strong bias towards deletion.
type RemoveResult = IO (Either SomeException ())