Skip to content

Instantly share code, notes, and snippets.

View Sophia-Gold's full-sized avatar

Sophia Gold Sophia-Gold

View GitHub Profile
{ pkgs }:
{
allowUnfree = true;
allowBroken = true;
packageOverrides = self: with self; rec {
etsEnv = self.buildEnv {
name = "etsEnv";
@Sophia-Gold
Sophia-Gold / dft.clj
Last active January 13, 2018 08:33
Discrete Fourier Transform
(ns dft.core)
(defn fft [x]
(let [length (count x)]
(if (<= length 1)
(->> x
(persistent!)
(vec))
(let [x (transient x)
even (recur (map #(nth % x) (range length)))
@Sophia-Gold
Sophia-Gold / dlet.clj
Created February 12, 2018 00:04
clojure macro for debugging let bindings
;; From e.g. https://github.com/scottjad/uteal
(defmacro dlet
"let with inspected bindings"
[bindings & body]
`(let [~@(mapcat (fn [[n v]]
(if (or (vector? n) (map? n))
[n v]
[n v '_ `(println (name '~n) ":" ~v)]))
(partition 2 bindings))]
~@body))
@Sophia-Gold
Sophia-Gold / inspect-thread.clj
Created February 12, 2018 00:06
debugging clojure thread macros
;; Version 1: direct inline the anonymous function:
(defn as-currency
"Money amounts are transmitted as \"$2.44\".
Parse this and return a numeric type."
[currency-amount]
(-> (subs currency-amount 1)
((fn [x] (println x) x))
(bigdec)
((fn [x] (println x) x))))
(defmacro loop-while
[bind condition & body]
`(loop ~bind
(when ~condition
~@body
(recur ~@(map second (partition 2 bind))))))
@Sophia-Gold
Sophia-Gold / quine.scm
Created March 1, 2018 08:00
canonical Scheme quine
((lambda (x) (list x (list 'quote x)))
'(lambda (x) (list x (list 'quote x))))
@Sophia-Gold
Sophia-Gold / dlist.clj
Created March 17, 2018 03:29
Difference Lists in Clojure
(defn dl
[& elements]
(fn [x] (concat elements x)))
(defn dl-un
[l]
(l nil))
(defn dl-concat
[& lists]
(fn [x] ((apply comp lists) x)))
@Sophia-Gold
Sophia-Gold / LOC.sh
Last active July 30, 2019 08:43
count LOC with git
#!/bin/bash
git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904
@Sophia-Gold
Sophia-Gold / ones-in-partitions.clj
Created March 28, 2018 05:56
two ways to count the number of 1s in all partitions of a given integer
(defn ones-in-partitions
"Number of 1s in all partitions of an integer n"
[n]
(-> (repeat (dec n) 1)
(clojure.math.combinatorics/partitions)
(count)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn partitions
@Sophia-Gold
Sophia-Gold / Montgomery.hs
Created April 4, 2018 07:11
Montgomery multiplication in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverlappingInstances #-}
module Montgomery where
-- type R = 2
r :: Integer
r = 2