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 DepthFirstSearch where | |
import Data.Foldable (asum) | |
import Data.List ((\\)) | |
dfs :: (Eq a) => (a -> [a]) -> a -> a -> Maybe [a] | |
dfs next start goal = dfs' [] start | |
where dfs' path current | |
| current == goal = Just . reverse $ goal : path | |
| null nexts = Nothing |
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
(ns postgres.upsert | |
(:require [honeysql.core :as sql] | |
[clojure.java.jdbc :as jdbc] | |
[clojure.string :as str] | |
[clojure.set :as set])) | |
(defn- keyword->colname [kwd] | |
(-> kwd | |
name | |
(str/replace #"-" "_"))) |
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
CREATE OR REPLACE FUNCTION ilog2(v integer) | |
RETURNS integer AS | |
$$ | |
DECLARE | |
r integer; | |
shift integer; | |
BEGIN | |
IF v > x'FFFF'::integer THEN r := 1 << 4; ELSE r := 0 << 4; END IF; | |
v := v >> r; | |
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 RecordWildCards #-} | |
module Main where | |
import qualified Data.Map as Map | |
import Control.Monad.State | |
import System.Random | |
import Data.Maybe | |
import Debug.Trace | |
main :: IO () |
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 Calc | |
( Expr(..) | |
, parse | |
, calculate | |
) where | |
import Control.Applicative | |
import Parser | |
data Expr = Add Expr Expr |
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 Treap | |
( Treap (..) | |
, empty | |
, null | |
, insert | |
, delete | |
, member | |
, size | |
, rInsert | |
, rFromList |
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
# Finds all maximal cliques in a graph using the Bron-Kerbosch algorithm. The input graph here is | |
# in the adjacency list format, a dict with vertexes as keys and lists of their neighbors as values. | |
# https://en.wikipedia.org/wiki/Bron-Kerbosch_algorithm | |
from collections import defaultdict | |
def find_cliques(graph): | |
p = set(graph.keys()) | |
r = set() | |
x = set() |
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 qualified Data.PQueue.Prio.Min as PQ | |
import qualified Data.HashSet as Set | |
import qualified Data.HashMap.Strict as Map | |
import Data.Hashable (Hashable) | |
import Data.List (foldl') | |
import Data.Maybe (fromJust) | |
astarSearch :: (Eq a, Hashable a) => a -> (a -> Bool) -> (a -> [(a, Int)]) -> (a -> Int) -> Maybe (Int, [a]) | |
astarSearch startNode isGoalNode nextNodeFn heuristic = | |
astar (PQ.singleton (heuristic startNode) (startNode, 0)) |
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 sys | |
import os | |
import itertools | |
import re | |
import traceback | |
import time | |
import mechanize | |
from functools import wraps | |
from urllib import urlretrieve |
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
gnome-terminal --geometry=80x100+450 -x sh -c \ | |
"xclip -o | tr -cd '[:alpha:]' | python -c 'import sys, inflection; print inflection.singularize(sys.stdin.readline())' | xargs dict | less" |