Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@virtualsafety
virtualsafety / ddns.go
Created December 24, 2012 14:23 — forked from hugozhu/ddns.go
package main
import (
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"strings"
"time"
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"io"
"log"
"net"
// Implementation of a UDP proxy
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
import Control.Monad.State
import Control.Monad.Identity
import Data.Char(toUpper)
test1 :: State Int (Int,Int)
test1 = do
a <- get
modify (+1)
b <- get
@virtualsafety
virtualsafety / Fibonacci_campare.txt
Last active December 23, 2015 11:59
Fibonacci数列两种实现方式效率比较
keliven@keliven:~/haskell_example$ cat fib_3.hs
import System.Environment
fib = 0:1:(zipWith (+) fib (tail fib))
main = do
args <- getArgs
print $ (fib !!) $ read $ args !! 0
module Main where
import Text.Parsec
import Text.Parsec.String
input_text :: String
input_text = "foo123:"
main :: IO ()
main = do
module AVLTree where
data BT = L | N Int BT BT deriving (Show, Eq)
-- Nice, small and useful functions
empty = L
-- You could say, depth L == Nothing depth (N v L L) == Just 0, but works for
-- me better this way:
depth L = 0
depth (N _ t u) = (max (depth t) (depth u)) + 1
import Data.Maybe (isJust)
data Tree a = Leaf | Node (Tree a) a (Tree a)
replace :: a -> Tree a -> Tree a
replace a Leaf = Node Leaf a Leaf
replace a (Node l _ r) = Node l a r
rotateR :: Tree a -> Tree a
rotateR (Node (Node x a y) b z) = Node x a (Node y b z)
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module RedBlackTree where
data Zero
data Succ n
type One = Succ Zero
data Black