Skip to content

Instantly share code, notes, and snippets.

@mgsloan
mgsloan / pre-commit
Last active November 26, 2017 10:48
pre-commit hook to ensure no ignored files are in the commit (even if you used "git add --force")
#!/bin/sh
# Copyright 2017 Michael Sloan
# This file is MIT licensed.
changed="$(git diff --name-only --cached)"
changed_and_ignored="$(echo "$changed" | git check-ignore --stdin --no-index | tr -d '[:space:]')"
if test -z "$changed_and_ignored" ;
then
@mgsloan
mgsloan / MIT-LICENSE.md
Created November 26, 2017 08:22
MIT license applies to all my public gists

All public gists which do not specify a different license, listed at https://gist.github.com/mgsloan, are covered by the MIT License, http://www.opensource.org/licenses/mit-license.php

Copyright 2017 Michael Sloan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT H

fn main() {
let mut x = 1;
wat(|i| { x += i; return x; });
println!("{}", x);
}
fn wat<F>(f: F) -> u32 where F: FnMut(u32) -> u32 {
foo(f)
}
@mgsloan
mgsloan / a_summary
Last active February 5, 2016 14:28
Using new-stack to build old-stack, using it to build itself, and then using old-stack to build new-stack. new-stack is stack-1.0.3, the current release, and old-stack is stack-0.1.0.0, the first stable release 7 months ago.
mgsloan@computer:~/fpco/stack$ git checkout v0.1.0.0
...
mgsloan@computer:~/fpco/stack$ stack build
...
Installing executable(s) in
/home/mgsloan/fpco/stack/.stack-work/install/x86_64-linux/lts-2.9/7.8.4/bin
Registering stack-0.1.0.0...
Completed 123 action(s).
@mgsloan
mgsloan / Vacuum.hs
Last active December 20, 2015 04:09
import GHC.Vacuum
import GHC.Vacuum.GraphViz
import Data.GraphViz
lazyVacuumToPng :: FilePath -> a -> IO FilePath
lazyVacuumToPng fp x = graphToDotFile fp Png $ nameGraph (vacuumLazy x)
main :: IO ()
main = do
lazyVacuumToPng "beforeForce" xs
@mgsloan
mgsloan / gist:6050213
Last active December 20, 2015 01:39 — forked from wcauchois/gist:6050119
GeocodeResponse latLng <- callJsonEndpoint $ GeocodeEndpoint targetAddress False
let venuesTrendingEndpoint = VenuesTrendingEndpoint latLng Nothing Nothing `authorizeWith` creds
VenuesTrendingResponse venues <- callJsonEndpoint venuesTrendingEndpoint
let printVenue v = putStrLn $ "- " ++ name v
mapM_ printVenue venues
#!/bin/bash
ext=$1
rsync -aL --delete ~/fpco/ide/ ~/build/fpco-$ext/
cd ~/build/fpco-$ext
perl -i -pe "s~/fpco/ide/~/build/fpco-$ext/~g;" \
.hsenvs/*/.hsenv/bin/activate \
@mgsloan
mgsloan / Bar.hs
Last active December 10, 2015 01:48 — forked from anonymous/Bar.hs
module Bar where
bar = answer * 20
@mgsloan
mgsloan / gist:4186049
Created December 2, 2012 00:11
transitive descendents
import Control.Applicative
import Control.Lens
import Data.Data
import Data.Data.Lens
descendents :: (Data a, Data b) => (b -> Bool) -> Fold a b
descendents p f = biplate go
where
go x
| p x = f x
@mgsloan
mgsloan / blah.hs
Created April 7, 2012 19:35
Lined up variant
zipProducers :: Producer a m r -> Producer b m r -> Producer (a, b) m r
zipProducers (Pure r) _ = return r
zipProducers _ (Pure r) = return r
zipProducers (M m1) (M m2) = lift m1 >>= \p1 -> lift m2 >>= \p2 -> zipProducers p1 p2
zipProducers (M m1) p2 = lift m1 >>= \p1 -> zipProducers p1 p2
zipProducers p1 (M m2) = lift m2 >>= \p2 -> zipProducers p1 p2
zipProducers (Await f1) (Await f2) = zipProducers (f1 ()) (f2 ())
zipProducers (Await f1) p2 = zipProducers (f1 ()) p2