Skip to content

Instantly share code, notes, and snippets.

;; init-basic.el
;; A barebones emacs init file for beginners. Removes most common annoyances.
;;
;; Author: Matthew Chan <matt@themattchan.com>
;; Date: November 2014, Last updated January 2015
;; License: GNU GPL
;;
;; Usage: Put in .emacs.d as init.el. Run
;; $ cd
;; $ git clone https://gist.github.com/112f4a71294aec281fa9.git .emacs.d
# AsideBlock
# Insert toggle-able text segments with ease in Jekyll blog posts.
# Requires Bootstrap
#
# Author: Matthew Chan <matt@themattchan.com>
# Date: January 2015
# License: GNU GPL
#
# Usage:
# {% aside <title> %} ==> auto expands to "(aside) <title>"
# MarkdownBlock
# Insert & parse Markdown anywhere, even nested in html
#
# Author: Matthew Chan <matt@themattchan.com>
# Date: January 2015
# License: GNU GPL
#
# Usage:
# {% markdown %}
# <md_text>
module Golf where
import Data.List
skips :: [a] -> [[a]]
skips xs = map (map snd) $ zipWith filter filters (replicate len ids)
where len = length xs
ids = zip [1..len] xs
filters = map (\n (a,_) -> a `mod` n == 0) [1..len]
localMaxima :: [Integer] -> [Integer]
#lang racket
#|
Simplified SXML grammar
<Element> ::= (<Symbol> <Children>...)
| (<Symbol> <AttribList> <Children>...)
<Children> ::= <Element> | <Value>
<AttribList> ::= (<Attribute> ...) | (@ <Attribute> ...)
#lang racket
(require test-engine/racket-tests)
(define (rotations lst)
(letrec ((go (λ (n acc)
(if (= n 0) acc
(go (sub1 n) (let ((c (car acc)))
`(,`(,@(cdr c) ,(car c)) ,@acc)))))))
(reverse (go (length lst) (list lst)))))
@themattchan
themattchan / SEXPRS FTW
Last active November 15, 2015 04:29
fuck xml.
#lang racket
(require xml)
(require xml/xexpr)
(define to-html (compose display
xexpr->string))
(define CONFIGS '((siteName "Andromeda")
(latitude 1234.567)
@themattchan
themattchan / DFA.hs
Last active November 15, 2015 04:29
{- LANGUAGE TupleSections -}
import Control.Monad
import qualified Data.Set as S
--type State = String
type Symbol = Char
data DFA st = DFA { states :: [st],
alphabet :: [Symbol],
delta :: st -> Symbol -> st,
startSt :: st
(* Folds *)
let rec fold_right f a xs = match xs with
| [] -> a
| x :: xs -> f (fold_right f a xs) x
let rec fold_left f a xs = match xs with
| [] -> a
| x :: xs -> fold_left f (f a x) xs
(* TODO: implement monoids and the foldable typeclass with modules*)
%
% Listings hacks to emulate the math-style Haskell from Functional Pearls,
% Programming in Haskell, Pearls of Functional Algorithm Design. and other books.
%
% This is probably as close an emulation of the math-style generated with lhs2tex as I can get.
%
% Modified from:
% https://raw.githubusercontent.com/UCSD-PL/230-web/master/templates/haskellListings.tex
%