Skip to content

Instantly share code, notes, and snippets.

View eHammarstrom's full-sized avatar
🐚
script

Emil Hammarström eHammarstrom

🐚
script
  • Sweden
View GitHub Profile
@eHammarstrom
eHammarstrom / tree_n_linkedlist.hs
Last active April 4, 2018 21:14
tree & linked lists
module Main where
data Tree a = Leaf a | Node (Tree a) (Tree a)
deriving (Eq, Show)
tree = Node (Leaf "a") (Node (Leaf "b") (Node (Leaf "c") (Leaf "d")))
countTree :: Tree a -> Integer
countTree (Leaf _) = 1
countTree (Node l r) = countTree l + countTree r
@eHammarstrom
eHammarstrom / bin.py
Created April 4, 2018 22:15
binary search
fake_list = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]
def has_elem(x, xs):
length = len(xs) - 1
right = length
left = 0
mid = (right - left) / 2
while True:
optAlignments' :: String -> String -> [AlignmentType]
optAlignments' xs ys = snd $ get (length xs) (length ys)
where
get i j = table !! i !! j
table = [[ entry i j | j <- [0..] ] | i <- [0..] ]
entry :: Int -> Int -> (Int, [AlignmentType])
entry i j
| i == 0 && j == 0 = (0, [([], [])])
| i == 0 = (j * scoreSpace, (attachTails '-' y . snd) $ get 0 (j-1))
| j == 0 = (i * scoreSpace, (attachTails x '-' . snd) $ get (i-1) 0)
➜ RealParser git:(master) ✗ nix-shell -A RealParser.env
[nix-shell:~/git/RealParser]$ runhaskell Setup.hs configure
Configuring RealParser-0.1.0.0...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
[nix-shell:~/git/RealParser]$ runhaskell Setup.hs repl
Setup.hs: The 'repl' command does not support multiple targets at once.
[nix-shell:~/git/RealParser]$
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
module Parser
( Parser (..), execParser, runParser
, ParseError (..), unexpected
, ParseState (..), input, location, previousToken, indentation
-- Parser functions
, char, satisfy, letter, digit, number, float -- Primitives
import Control.Lens
import Test.Tasty
import Test.Tasty.HUnit
import Parser
defaultPs :: ParseState
defaultPs = ParseState "" (0,0) "" []
ps1 :: ParseState
ps1 = input .~ ".123" $ defaultPs
/Users/ehammarstrom/git/RealParser/test/Spec.hs:18:27: error:
• No instance for (transformers-0.5.2.0:Control.Monad.Trans.Error.Error
ParseError)
arising from a use of ‘satisfy’
• In the first argument of ‘runParser’, namely
‘(satisfy "dot" (== '.'))’
In the expression: runParser (satisfy "dot" (== '.')) ps1
In an equation for ‘t1’:
t1 = runParser (satisfy "dot" (== '.')) ps1
|
@eHammarstrom
eHammarstrom / settings.json
Last active May 21, 2020 21:33
vscode-vim-dvorak
{
"vim.normalModeKeyBindingsNonRecursive": [
{ "before": ["t"], "after": ["g", "j"] },
{ "before": ["n"], "after": ["g", "k"] },
{ "before": ["h"], "after": ["h"] },
{ "before": ["s"], "after": ["l"] },
{ "before": ["S"], "after": ["L"] },
{ "before": ["j"], "after": ["s"] },
{ "before": ["J"], "after": ["S"] },
{ "before": ["T"], "after": ["J"] },
@eHammarstrom
eHammarstrom / keybindings.json
Last active July 9, 2018 06:45
vscode-vim-dvorak
[
{
"key": "shift+ctrl+h",
"command": "workbench.action.navigateLeft"
},
{
"key": "shift+ctrl+s",
"command": "workbench.action.navigateRight"
},
{
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 4))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))