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 Main where | |
import Prelude | |
import Control.Plus (empty) | |
import Data.Array as A | |
import Data.Set as S | |
import Control.Monad.Eff.Console (log) | |
import Data.Foldable (minimum, maximum) | |
import Data.Maybe (fromMaybe) | |
import Data.String (joinWith, fromCharArray) |
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 com.codepoetics.kontinuous | |
import java.sql.Connection | |
import java.sql.PreparedStatement | |
import java.sql.ResultSet | |
data class Foo(val a: String, val b: Int, val c: Double) | |
interface RowN { | |
val selectSql: String |
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.Map as Map | |
type SubPaths = Map.Map String Node | |
data Node = Content SubPaths | NoContent SubPaths deriving (Show) | |
content :: [(String, Node)] -> Node | |
content kvs = Content $ Map.fromList kvs | |
nocontent :: [(String, Node)] -> Node | |
nocontent kvs = NoContent $ Map.fromList kvs |
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.function.*; | |
public final class Tunnel<E extends Exception> { | |
public static <E extends Exception, R> R call(Class<? extends E> exceptionClass, Function<Tunnel<E>, R> f) throws E { | |
try { | |
return f.apply(new Tunnel<>()); | |
} catch (TunnelledException e) { | |
throw exceptionClass.cast(e.getCause()); | |
} |
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
public class RotationalHash { | |
public static int hash(String beads) { | |
byte[] buf = beads.getBytes(); | |
int hash = hashBytes(buf); | |
int i = 0; | |
int j = buf.length - 1; | |
while (i < j) { | |
buf[i] ^= buf[j]; | |
buf[j] ^= buf[i]; |
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
@FunctionalInterface | |
public interface Judiciously<T> { | |
class WrappedException extends RuntimeException { | |
public WrappedException(Throwable cause) { | |
super(cause); | |
} | |
} | |
static <T> T attempt(Judiciously<T> f) { |
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
public interface Nonchalantly<T> { | |
static <T, E extends Throwable> T invoke(Nonchalantly<T> f) throws E { | |
try { | |
return f.run(); | |
} catch (Throwable e) { | |
throw (E) e; | |
} | |
} | |
T run() throws Throwable; | |
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 Main | |
forLoop : List a -> (a -> IO ()) -> IO () | |
forLoop [] f = return () | |
forLoop (x :: xs) f = do f x | |
forLoop xs f | |
syntax for {x} "in" [xs] ":" [body] = forLoop xs (\x => body) | |
spaces : Nat -> String |
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 random | |
def memoize(f): | |
cache = {} | |
def memoized(*arg): | |
if arg in cache: | |
return cache[arg] | |
result = f(*arg) | |
cache[arg] = result | |
return result |
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 com.codepoetics.hume; | |
import static org.hamcrest.MatcherAssert.assertThat; | |
import static org.hamcrest.Matchers.equalTo; | |
import org.junit.Test; | |
import com.codepoetics.hume.api.Property; | |
import com.codepoetics.hume.api.Record; | |
import com.codepoetics.spinoza.Compose; |