Skip to content

Instantly share code, notes, and snippets.

Alan Malloy amalloy

Block or report user

Report or block amalloy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View zip-stratify.clj
(defn stratify [coll]
(z/root (reduce (fn [loc x]
(let [prev (z/node loc)]
(cond (= x prev) (-> loc (z/insert-right x) (z/right))
(> x prev) (-> loc (z/insert-right [x]) (z/right) (z/down))
:else (-> loc (z/up) (z/insert-right x) (z/right)))))
(-> (z/vector-zip [(first coll)])
(z/down))
(rest coll))))
View gist:8db634bcec85c33c0902e53581e90884
(defn stratify [coll]
(:ret ((fn step [coll]
(loop [ret [], coll coll]
(if (empty? coll)
{:ret ret :remainder nil}
(let [x (first coll)
[same different] (split-with #(= % x) coll)
so-far (into ret same)
pending (seq different)]
(cond (nil? pending) {:ret so-far :remainder nil}
View monoid.hs
import Data.Semigroup (stimes)
newtype Product = Product Integer
instance Semigroup Product where
Product x <> Product y = Product $ x * y
instance Monoid Product where
mempty = Product 1
View git-permissions.sh
$ touch tmp
$ git hash-object tmp
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
$ chmod +x tmp
$ git hash-object tmp
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
View repro.clj
;; consumes all memory
((fn foo [s]
((^:once fn bar []
(last s))))
(range))
;; bytecode inspection summary: foo clears its local copy of s, but bar never clears its closed-over copy
;; disassembly of bar:
user> (println (disassemble-str
View recent won.txt
`!lg * recent / won` produces 2 queries, and divides one by the other. Here's the numerator:
explain analyze SELECT COUNT(*) AS fieldcount FROM logrecord
INNER JOIN l_ktyp ON logrecord.ktyp_id = l_ktyp.id
INNER JOIN l_cversion ON logrecord.cv_id = l_cversion.id
WHERE ((l_ktyp.ktyp = 'winning') AND (l_cversion.cvnum >= '2200099000000'::bigint));
Aggregate (cost=446001.87..446001.88 rows=1 width=8) (actual time=9661.391..96
61.391 rows=1 loops=1)
-> Hash Join (cost=4909.80..445813.68 rows=75274 width=0) (actual time=1912
View gist:2b463fa92df50bf872f77edb2bd9937d
query plan for `lm *`:
------------------------------------------------------------------------------------------------------------------------------------------------------
Finalize Aggregate (cost=2406794.84..2406794.85 rows=1 width=8) (actual time=47772.901..47772.901 rows=1 loops=1)
-> Gather (cost=2406794.62..2406794.83 rows=2 width=8) (actual time=47772.832..47774.309 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Partial Aggregate (cost=2405794.62..2405794.63 rows=1 width=8) (actual time=47769.615..47769.615 rows=1 loops=3)
-> Parallel Seq Scan on milestone (cost=0.00..2356329.70 rows=19785970 width=0) (actual time=0.121..45652.718 rows=15828777 loops=3)
View Main.hs
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Control.Arrow ((&&&))
import Control.Monad (replicateM)
import Data.Functor.Foldable (Fix, cata)
import qualified Data.IntMap.Lazy as M
import Text.Parsec.Char (spaces, digit, char)
import Text.Parsec.String (Parser)
View gist:841addcd5073ead2e358376e016134fb
Program received signal SIGABRT, Aborted.
raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x000056352d3e4ca9 in _BreakStrToDebugger (
mesg=0x7ffdee9d0220 "ASSERT(you.props.exists(sac_def.sacrifice_vector)) in 'god-abil.cc' at line 5311 failed.", assert=true) at dbg-asrt.cc:808
#2 0x000056352d3e4e8d in AssertFailed (
expr=0x56352dc5aeb0 "you.props.exists(sac_def.sacrifice_vector)",
file=0x56352dc57b7d "god-abil.cc", line=5311, text=0x0) at dbg-asrt.cc:846
View signal.hs
instance Monad Signal where
return = pure
(Signal s) >>= f = Signal $ \t -> let Signal s' = f (s t)
in s' t
-- or, equivalently but less readably:
-- s >>= f = Signal $ join (func . f . func s)
You can’t perform that action at this time.