This file contains hidden or 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 RBTree : sig | |
type 'a t | |
val empty : 'a t | |
val insert : 'a t -> 'a -> 'a t | |
val exists : 'a t -> 'a -> bool | |
val remove : 'a t -> 'a -> 'a t | |
val fold_left : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b | |
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b | |
val balanced : 'a t -> bool | |
val from_list : 'a list -> 'a t |
This file contains hidden or 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 {actionCreators, Action} from '../actions/Action' | |
export class App extends React.Component<AppProps, {}> { | |
public static childContextTypes: any = {} | |
private getChildContext() { | |
const context: any = {} | |
const props = this.props as any | |
Object.keys(this.props).forEach(prop => { | |
if (typeof props[prop] == 'function' && prop in actionCreators) { |
This file contains hidden or 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 MultiParamTypeClasses, FunctionalDependencies #-} | |
-- works too | |
class Message params msg | msg -> params, params -> msg where | |
create :: params -> msg | |
data FooMessage = FooMessage { from, to :: Int } deriving (Show) | |
data FooMessageParams = FooMessageParams { _from, _to :: Maybe Int } |
This file contains hidden or 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 asyncdispatch | |
type KeyNotFoundError* = object of IOError | |
proc get*(key: string): Future[string] = | |
let res = newFuture[string]() | |
sleepAsync(500).callback = proc(future: Future[void]) {.closure, gcsafe.} = | |
if key != "hello": | |
res.fail(newException(KeyNotFoundError, "Key " & key & " is not found")) | |
else: |
This file contains hidden or 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
proc get*(client: MemcacheAsyncClient, key: string): Future[string] = | |
let res = newFuture[string]() | |
client.sendCommand(CommandOpcode.Get, key = key.toRawData()).callback = proc(future: Future[Response]) {.closure, gcsafe.} = | |
let response = future.read() | |
if response.header.status == ResponseStatus.KeyNotFound: | |
res.fail(newException(KeyNotFoundError, "Key " & key & " is not found")) | |
else: | |
res.complete(response.value) | |
res |
This file contains hidden or 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
proc enumDef(x: NimNode): NimNode = | |
result = quote do: | |
type `x` = enum enOne, enTwo | |
macro one(x): stmt {. immediate .} = | |
echo treeRepr(x) | |
result = enumDef(x) | |
echo treeRepr(result) | |
one SuperEnum |
This file contains hidden or 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 macros, strutils | |
from sockets import ntohl, ntohs, htons, htonl | |
import endians | |
export sockets.ntohl | |
export sockets.ntohs | |
export sockets.htonl | |
export sockets.htons | |
const bigInts = ["int16", "uint16", "int32", "uint32", "int", "uint", "int64", "uint64"] |
This file contains hidden or 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 parseopt, strutils, math | |
type | |
Options = object | |
a, b, step: float | |
report: int | |
filename: string | |
DataPoint = tuple[x: float, y: float] | |
Data = seq[DataPoint] |
This file contains hidden or 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 Control.Applicative ((<$>)) | |
import Data.List (partition) | |
import Data.Map (Map) | |
import qualified Data.Map as M | |
type Edge = [Int] | |
data Color = Red | Black deriving (Show, Eq) | |
type Paint = Map Int Color |
This file contains hidden or 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 Control.Applicative ((<$>)) | |
import Data.List (partition) | |
type Edge = [Int] | |
findCycle :: [Int] -> [Edge] -> Maybe [Int] | |
findCycle vs es = | |
if (not $ all (even . length . adjacent es) vs) || (segmentsCount vs es > 1) | |
then Nothing | |
else Just $ let (cycle, rest) = buildCycle (head vs) es in builder cycle rest |