Skip to content

Instantly share code, notes, and snippets.

View letsbreelhere's full-sized avatar

Bree Elle Gardner letsbreelhere

View GitHub Profile
@letsbreelhere
letsbreelhere / gist:5051c3fd57c726394c11b5c34f39d660
Last active October 20, 2023 17:12
Git overlay for master -> main muscle memory
#!/usr/bin/env python
import subprocess
import sys
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
@letsbreelhere
letsbreelhere / jarchive_parser.js
Created February 9, 2022 06:44
J! Archive Parser
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] = [];
})
@letsbreelhere
letsbreelhere / wordle.ijs
Last active January 11, 2022 22:51
Wordle autoplayer
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
)
@letsbreelhere
letsbreelhere / hoogle_flow.rb
Last active December 17, 2019 18:03
Hoogle Alfred flow
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}")
@letsbreelhere
letsbreelhere / Knights.hs
Last active July 19, 2017 22:51
Uncrossed Knight's Tours
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 []
@letsbreelhere
letsbreelhere / Element.hs
Last active July 6, 2017 21:44
Element spelling solution
module Element where
import Data.List (isPrefixOf, (\\), intercalate)
import Control.Monad (guard)
import Data.Char (toLower)
elements :: [(String, String)]
elements =
[ ("Ac", "Actinium")
, ("Ag", "Silver")
@letsbreelhere
letsbreelhere / LambdaToSki.hs
Last active May 29, 2022 20:16
Lambda Calculus -> SKI Calculus
{-# 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
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
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])
@letsbreelhere
letsbreelhere / gist:1ae5d72c0f6a5d0a2ee1
Last active August 29, 2015 14:10
Working Type Inferencer/Unifier
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