Skip to content

Instantly share code, notes, and snippets.

View nl253's full-sized avatar
🎯
Focusing

nl253

🎯
Focusing
View GitHub Profile
@nl253
nl253 / bag.erl
Created May 25, 2018 20:17
Multiset (Bag) in Erlang
-module(bag).
-export([new/0, from_list/1, flatten/1, insert/2, insert_many/3, remove/2, remove_many/3, remove_all/2, union/2, difference/2, contains/2, height/1, height_info/1, left/1, right/1]).
% -compile(export_all).
-type bag() :: nil | {any(), integer(), bag(), bag()}.
-spec new() -> bag().
new() -> nil.
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.function.Function;
import java.util.function.Predicate;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicReference;
@nl253
nl253 / SteepestDescent.java
Last active May 19, 2018 16:54
Steepest Descent in Java
import java.security.SecureRandom;
import java.time.LocalTime;
import java.util.Random;
import java.util.function.BinaryOperator;
import java.util.logging.Logger;
import static java.lang.StrictMath.abs;
import static java.lang.StrictMath.pow;
import static java.time.LocalTime.now;
@nl253
nl253 / perceptron.go
Created May 17, 2018 18:54
Perceptron in Go
package main
import (
"fmt"
"os"
"regexp"
"strings"
"time"
)
@nl253
nl253 / GraphSearching.hs
Last active April 27, 2018 13:46
Depth-First Search, Limited Depth-First Search, Iterative Deepening, Uniform-Cost Search, A* Algorithm in Haskell (not aiming for efficiency)
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module GraphSearching where
import Control.Applicative ((<|>))
import Control.Monad (join)
import Data.List (sortOn)
import Data.Maybe (isJust)
@nl253
nl253 / WriterMonad.hs
Created April 25, 2018 20:29
WriterMonad
module WriterMonad
( logInput
) where
import Control.Monad.Writer
import Data.Char (isDigit, isLetter, isLower,
isPunctuation, isSpace, isUpper)
logInput :: String -> [String]
logInput xs =
@nl253
nl253 / showFunctSignatureHoogle.vim
Last active April 14, 2018 20:45
Haskell - show function signature on cursor hold autocommand (uses hoogle)
let g:hoogled_signatures = {}
let g:hoogle_blacklist = [
\ 'where',
\ 'let',
\ 'class',
\ 'then',
\ 'module',
\ 'qualified',
\ 'data',
\ 'type',
@nl253
nl253 / hoogleProjectOmniFunct.vim
Last active April 14, 2018 21:02
Haskell OmniFunc - query hoogle and project file for functions with signatures etc
" NOTE: requires +timers
" cache storage
let g:hoogled_completions = {}
" non-function keywords
let g:hoogle_blacklist = [
\ 'where',
\ 'let',
@nl253
nl253 / CsvParser.hs
Created March 18, 2018 10:21
Csv parser
module Csv where
import Data.List (lines)
type Row = [String]
type Lines = [String]
type Table = [Row]