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 Numeric | |
import Data.Char | |
import Control.Monad | |
import Control.Applicative hiding (many, (<|>)) | |
import Text.Parsec | |
import Text.Parsec.String | |
data LLVal = IPv4 | IPv6 | MAC | Etc | |
deriving (Show, Eq) |
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
<?php | |
$hostname = '192.168.0.100'; | |
$port = 80; | |
$timeout = 10; | |
$sock = fsockopen($hostname, $port, $errono, $errstr, $timeout); | |
if ($sock === false) { | |
exit("{$errstr} ({$errono})\n"); | |
} | |
echo "connect {$hostname}:{$port}\n"; |
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 System.Random | |
import System.Time | |
import Control.Monad.State | |
main :: IO () | |
main = do | |
seed <- mkSeed | |
talk $ iSaid seed | |
mkSeed :: IO Int |
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 Data.List | |
import Test.QuickCheck | |
bubbleSort :: Ord a => [a] -> [a] | |
bubbleSort [] = [] | |
bubbleSort [x] = [x] | |
bubbleSort xs = bubbleSort zs ++ z | |
where | |
(zs, z) = splitAt (length xs - 1) $ bubble xs | |
bubble (y0:y1:ys) |
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 Data.List | |
import Test.QuickCheck | |
combSort :: Ord a => [a] -> [a] | |
combSort xs = comb (gap (length xs)) xs | |
comb :: Ord a => Int -> [a] -> [a] | |
comb h xs | |
| h <= 0 = xs | |
| h == 1 = let sorted = comb' in |
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 Data.List | |
import Test.QuickCheck | |
mergeSort :: (Ord a) => [a] -> [a] | |
mergeSort [] = [] | |
mergeSort [x] = [x] | |
mergeSort items = merge l' r' | |
where | |
(l, r) = halve items | |
l' = mergeSort l |
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 Data.List | |
import Test.QuickCheck | |
insertionSort :: Ord a => [a] -> [a] | |
insertionSort = foldr isort [] | |
where | |
isort x [] = [x] | |
isort x (y:ys) | |
| x > y = y : isort x ys | |
| otherwise = x : y : ys |
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 Data.List | |
import Test.QuickCheck | |
selectionSort :: Ord a => [a] -> [a] | |
selectionSort [] = [] | |
selectionSort xs = v : (selectionSort (extract i xs)) | |
where | |
(v, i) = findMin xs | |
findMin :: Ord a => [a] -> (a, Int) |
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 JSON where | |
import Control.Applicative hiding (many, (<|>)) | |
import Numeric | |
import Text.Parsec | |
import Text.Parsec.String | |
-- http://www.ietf.org/rfc/rfc4627.txt | |
data JValue = JBool Bool |
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
<?php | |
function fizzbuzz($fs, $bs, $i = 1) | |
{ | |
if ($i <= 100) { | |
$fs[] = $f = array_shift($fs); | |
$bs[] = $b = array_shift($bs); | |
printf('%s', $f . $b) || print $i; | |
echo PHP_EOL; | |
fizzbuzz($fs, $bs, $i + 1); | |
} |
OlderNewer