This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Ergonomic changes. | |
;;; These are for the Dvorak keyboard layout. | |
(defvar mrenaud-ergo-minor-mode-map (make-keymap) "mrenaud-ergo-minor-mode keymap.") | |
;; Movement commands: | |
;; Now lie on right hand homerow. | |
;; h t n s | |
;; < ^ v > | |
(define-key mrenaud-ergo-minor-mode-map (kbd "C-h") 'backward-char) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set bind-tty-special-chars off | |
Control-h: backward-char | |
"\eh": backward-word | |
Control-t: previous-history | |
Control-n: next-history | |
Control-s: forward-char | |
"\es": forward-word |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ParseUriQuery where | |
import Control.Applicative | |
import Data.Attoparsec.ByteString.Char8 | |
import Data.ByteString.Char8 (ByteString, pack, unpack) | |
import Data.Either | |
data QueryTerm = QueryTerm { termName :: ByteString | |
, termValue :: Maybe ByteString | |
} deriving (Eq, Read, Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
{-# OPTIONS_GHC -Odph #-} | |
import Prelude hiding (map, sum) | |
import qualified Data.ByteString.Char8 as S | |
import Data.List.Stream | |
main = S.getContents >>= print . sumOfSquares . parse | |
where sumOfSquares = sum . map (\x -> x * x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
{-# OPTIONS_GHC -Odph #-} | |
import qualified Data.ByteString.Char8 as S | |
import qualified Data.Vector as U | |
-- Read ints from stdin into a vector then print the length. | |
main = S.getContents >>= print . U.length . parse | |
-- Fill a new vector from a file containing a list of numbers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module FastParse (parseInts) where | |
import Prelude hiding (length) | |
import Control.Applicative hiding (empty) | |
import Control.Monad | |
import Data.Char | |
import Data.Maybe | |
import Data.Sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Timing breakdown: | |
-- Reading: 2.5s | |
-- Sorting: 3.5s | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Data.ByteString.Char8 (pack) | |
import Data.Attoparsec.ByteString.Char8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This version runs in ~0.7 seconds due to String actually being a linked list | |
-- of Char. Not super efficient. | |
main = do | |
chars <- head <$> getArgs | |
englishWords <- words <$> readFile "en.txt" | |
mapM_ putStrLn $ sortBy (comparing length) $ findValidWords chars englishWords | |
findValidWords :: String -> [String] -> [String] | |
findValidWords chars englishWords = filter (`canBeMadeWith` chars) englishWords |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f :: [[a]] -> Bool | |
f matrix = flattenedMatrix == (reverse flattenedMatrix) | |
where flattenedMatrix = concat matrix | |
-- Note that concat (defined in the default environment) simply flattens a list of lists into a list. | |
concat :: [[a]] -> [a] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using std::vector; | |
// Represents a matrix with the contents stored in row major order. | |
struct Matrix { | |
int numRows; | |
int numColumns; | |
vector<vector<int>> contents; |