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
defmodule CacheServer do | |
use GenServer | |
@name CS | |
## Client API | |
def start_link(opts \\ []) do | |
GenServer.start_link(__MODULE__, :ok, opts ++ [name: CS]) | |
end |
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
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
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
(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
# 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
package net.abhinavsarkar.util; | |
/** | |
* A (infinite) Fibonacci number generator. | |
* | |
* @author Abhinav Sarkar | |
*/ | |
public class Fibonacci extends Generator<Integer> { | |
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
import java.util.List; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.cache.Cache; | |
import org.springframework.cache.support.SimpleValueWrapper; | |
import com.google.common.base.Optional; | |
import com.google.common.cache.CacheBuilder; | |
import com.google.common.cache.CacheBuilderSpec; |
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 actors.Actor | |
import actors.Actor._ | |
object RingTopologySimulation extends Application { | |
case class Message(count: Int) | |
class Node(id: Int, stops: Int) extends Actor { | |
var next: Node = null |
NewerOlder