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
#!/usr/bin/env python | |
import subprocess | |
import sys | |
def getch(): | |
import sys, tty, termios | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) | |
try: |
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
import { parse } from 'node-html-parser'; | |
const parseRound = (clueRoot, responseRoot) => { | |
const categories: Array<string> = clueRoot.querySelectorAll('td.category_name').map(c => c.rawText); | |
const clues = clueRoot.querySelectorAll('td.clue'); | |
let result: Object<string, object> = {}; | |
categories.forEach(category => { | |
result[category] = []; | |
}) |
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
letters =: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
allWords =: > (#~ (5&=@>@(# each))) }: each cutLF fread 'scrabble.txt' | |
NB. Letters are scored by their frequency's nearness to 50% | |
NB. and duplicates are counted once, since they provide less information. | |
bestWord =: monad define | |
freqs =. (#y) %~ <: #/.~ letters , ,y | |
scores =. ((1 = freqs) * %10) + 0.5 - | 0.5 - freqs | |
score =. [: +/ {&scores@(letters&i.)@~. | |
{. y \: > score"1 y | |
) |
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
require 'nokogiri' | |
require 'json' | |
require 'net/http' | |
require 'cgi' | |
def sanitize(text) | |
CGI.unescapeHTML(Nokogiri::HTML(text).xpath('//text()').to_s) | |
end | |
query_str = URI.escape("{query}") |
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 Knights where | |
import Control.Monad (guard) | |
import Data.Tree | |
type Point = (Int, Int) | |
prune :: Int -> Tree a -> Tree a | |
prune n _ | n < 1 = error "Can't prune to height < 1" | |
prune 1 (Node x _) = Node 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
module Element where | |
import Data.List (isPrefixOf, (\\), intercalate) | |
import Control.Monad (guard) | |
import Data.Char (toLower) | |
elements :: [(String, String)] | |
elements = | |
[ ("Ac", "Actinium") | |
, ("Ag", "Silver") |
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 DeriveFunctor, FlexibleInstances, UndecidableInstances #-} | |
{- | |
A fun exercise: read lambda calculus expressions and convert them to | |
pointfree form in the SKI-calculus (see http://www.madore.org/~david/programs/unlambda/#lambda_elim). | |
Parsing (and output via Show) are written using the conventions at | |
the link above: | |
* Lambda-abstraction is written "^v.E" (equivalent to Haskell "\v -> E") | |
* Application is written "`lr" (equivalent to "l r") | |
Also, note that the conversion function gives binding priority to the |
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
import Data.Monoid ((<>)) | |
import Data.Text (Text) | |
import Text.Parsec | |
import Text.Parsec.Text | |
import qualified Data.Text as T | |
-- Replace all successful parses with a text transformation. E.g.: | |
-- λ> replaceParsed (read <$> many1 digit) (T.pack . show . (+1)) "foo42bar99baz12quux" | |
-- "foo43bar100baz13quux" | |
replaceParsed :: Parser a -> (a -> Text) -> Text -> Text |
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
escape :: [(Char, String)] -> String -> String | |
escape = foldr f id | |
where f (c,s) acc = acc . replaceOne (c,s) | |
replaceOne (c,s) = concatMap (\x -> if x == c then s else [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
module Inference where | |
-- This is extremely rough (a good bit is a gross amount of confusing mutual | |
-- recursion, and a few pieces just work without my understanding), but I | |
-- thought it'd be a good idea to get this down in case my laptop is hit with a | |
-- bus. | |
import Control.Applicative | |
import Data.Char | |
import Data.List |
NewerOlder