Skip to content

Instantly share code, notes, and snippets.

Avatar

James Adam Buckland ambuc

View GitHub Profile
@ambuc
ambuc / LaTeX macros
Last active Aug 29, 2015
useful custom macros for typesetting vector calculus in LaTeX
View LaTeX macros
%typeset \sgn as an upright operator name, like \sin. ex: \sgn(x)
\DeclareMathOperator{\sgn}{sgn}
%rename built-in command \v to \vaccent, to make room for...
\let\vaccent=\v
% ...\v, which typesets a bold, upright vector. ex: \v a
\renewcommand{\v}[1]{\ensuremath{\mathbf{#1}}}
% ... and \gv, which does the same for greek letters. ex: \gv\alpha
View .tmux.conf
# regular leader key
set -g prefix 'C-b'
bind-key 'C-b' send-prefix
set -g default-terminal "screen-256color"
set -sg escape-time 0 #Escape works without delay, important for Vim
#Star window and pane indexing at 1
set -g base-index 1
set -g pane-base-index 1
View .vimrc
" CUSTOM .VIMRC by JAMES BUCKLAND
" james.adam.buckland@gmail.com
" created June 01 2014
" :so %
"
"PLUGINS
call pathogen#infect() " enable pathogen extention handler
filetype plugin indent on " idk, something to do with plugins
set laststatus=2 " i'll be honest, i have no idea what this does. but it makes
@ambuc
ambuc / oracle.hs
Created Apr 29, 2017
Aaronson Oracle
View oracle.hs
import Data.Map as M
import Data.Maybe
import Numeric
learn :: [Bool] -> Map [Bool] Double -> Map [Bool] Double
learn hist brain = Prelude.foldr learn' brain [3..5]
where learn' n = M.insertWithKey (const (+)) (take n hist) 1.0
guess :: Map [Bool] Double -> [Bool] -> Bool
guess brain hist = wAvg (Prelude.map guess' [2..4]) >= 0.5
@ambuc
ambuc / tough_puzzle.hs
Created Apr 29, 2017
One Tough Puzzle
View tough_puzzle.hs
import Data.List
import Data.List.Split (chunksOf)
import Data.Char
data Suit = Club | Heart | Diamond | Spade deriving (Show, Read, Eq)
data Sex = Out | In deriving (Show, Read, Eq)
data Side = Side { suit :: Suit , sex :: Sex} deriving (Show, Read)
instance Eq Side where x == y = (suit x == suit y) && (sex x /= sex y)
data Piece = Piece { north :: Side , east :: Side
, south :: Side , west :: Side } deriving (Show, Read, Eq)
@ambuc
ambuc / graph.dot
Last active Apr 30, 2017
A Painting Puzzle
View graph.dot
digraph G {
size = "4,4";
"[1,1,1,1]" -> "[1,1,2]" [label="1"];
"[1,1,2]" -> "[1,1,2]" [label="1/2"];
"[1,1,2]" -> "[1,3]" [label="1/3"];
"[1,1,2]" -> "[2,2]" [label="1/6"];
"[1,3]" -> "[1,3]" [label="1/2"];
"[1,3]" -> "[2,2]" [label="1/4"];
"[1,3]" -> "[4]" [label="1/4"];
"[2,2]" -> "[1,3]" [label="2/3"];
@ambuc
ambuc / crossword.hs
Last active May 28, 2017
Puzzle Pong - Generating All Possible 4x4 Crosswords
View crossword.hs
import qualified Control.Monad as N (forM)
import qualified Data.Maybe as B (isJust, isNothing, fromJust, catMaybes)
import qualified Data.Char as C (isAsciiLower)
import qualified Data.Function as F (on)
import qualified Data.List as L (all, nub, groupBy, intercalate)
import qualified Data.List.Split as L (chunksOf)
import qualified Data.Map.Strict as M (Map, insert, empty, unions, findWithDefault)
import qualified Language.Words as W (allStringWords)
type Box = Maybe Char
@ambuc
ambuc / successive-rows.hs
Created Jul 15, 2017
Successive Rows of Horizontal, Straight Lines from Top to Bottom, and Vertical, Straight Lines from Left to Right, 1972
View successive-rows.hs
import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture
import Graphics.Rasterific.Transformations
import Data.List
refl = transform $ applyTransformation
Transformation { _transformA = 0.0, _transformC = 1.0, _transformE = 0.0,
_transformB = 1.0, _transformD = 0.0, _transformF = 0.0
}
@ambuc
ambuc / irrev-cube.hs
Created Aug 24, 2017
Puzzle Pong - Irreversible Cube I
View irrev-cube.hs
import Codec.Picture( PixelRGBA8( .. ), writePng, Image)
import Control.Arrow (first,second)
import Data.Function (on)
import Data.List (sort, nub, sortBy, groupBy, nubBy, delete, zip4, (\\), zipWith4)
import Data.List.Split (chunksOf)
import Data.Monoid ((<>))
import Data.Ord (comparing)
import Debug.Trace (trace)
import Graphics.Rasterific
import Graphics.Rasterific.Texture (uniformTexture)
View Isometric.hs
module Isometric
( Obj (..) , World , isometric , mark , render , seenFrom , solid
) where
import Codec.Picture (PixelRGBA8 (..), writePng, Image)
import Data.Monoid ((<>))
import Data.Function (on)
import Data.List (transpose, genericLength, sortBy)
import Data.Ord (comparing)
import Data.Matrix (Matrix, fromList, toList, transpose)