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
#! /usr/bin/ruby | |
require 'webrick' | |
mimetypes = WEBrick::HTTPUtils::DefaultMimeTypes | |
mimetypes["js"] = "application/x-javascript" | |
mimetypes["svg"] = "image/svg+xml" | |
s = WEBrick::HTTPServer.new(:Port => 8000, | |
:DocumentRoot => Dir::pwd, |
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
;; ~/.emacs.d/init.el | |
;; basic editing | |
(defun scroll-n-lines-ahead (&optional n) | |
"Scroll ahead N lines (1 by default)." | |
(interactive "P") | |
(scroll-up (prefix-numeric-value n))) | |
(defun scroll-n-lines-behind (&optional 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
data XMLItem = XMLElem String [(String, String)] [XMLItem] | |
| Text String | |
attrsShow as = concat [" " ++ k ++ "=\"" ++ v ++ "\"" | (k, v) <- as] | |
instance Show XMLItem where | |
show (Text s) = s | |
show (XMLElem tag as []) = "<" ++ tag ++ attrsShow as ++ " />" | |
show (XMLElem tag as cs) = "<" ++ tag ++ attrsShow as ++ ">" ++ | |
concatMap show cs ++ |
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 GCJ (runSolver) where | |
runSolver :: (Int -> [String] -> [a]) -> | |
(a -> String) -> | |
String -> String | |
runSolver splitter solver s = | |
let ls = lines s | |
n = read $ head ls | |
ins = splitter n $ tail ls | |
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
module Main (main) where | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
import Data.Word | |
import Data.Int | |
import Data.Bits | |
class Packable a where |
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
-- http://d.hatena.ne.jp/tanakh/20100824 | |
module Iteratee where | |
import Control.Applicative (Applicative, pure, (<*>)) | |
import Data.Maybe (catMaybes) | |
import System.IO (Handle, hIsEOF, hGetChar, openFile, hClose) | |
import System.IO (IOMode (ReadMode)) | |
import Control.Exception (bracket) | |
import Control.Monad ((>=>)) | |
import Control.Monad.Trans (MonadTrans, lift) |
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
{-# LANGUAGE OverloadedStrings #-} | |
-- http://d.hatena.ne.jp/kazu-yamamoto/20110216/1297845048 | |
import Control.Monad.IO.Class (liftIO) | |
import qualified Data.ByteString as BS | |
import qualified Data.ByteString.Char8 as B -- for OverloadedString | |
import Data.Enumerator (($$), (<==<), ($=), (=$)) | |
import qualified Data.Enumerator as E | |
import Data.Enumerator.Binary as EB |
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
-- http://d.hatena.ne.jp/fumokmm/20110815/1313405510 | |
import Data.List (find) | |
makeAlist :: [String] -> [(Int, String)] | |
makeAlist [] = [] | |
makeAlist (a:b:rest) = (read a, b):makeAlist rest | |
fizzbuzz :: [(Int, String)] -> [String] | |
fizzbuzz alist = map f [1..] |
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 Control.Applicative ((<$>), (*>), (<*)) | |
import Text.Parsec (many1, option, oneOf, spaces, upper, char, digit, | |
noneOf, parseTest, (<|>)) | |
import Text.Parsec.String (Parser, parseFromFile) | |
import Data.Char (ord) | |
import Prelude hiding (sequence, seq) | |
-- data Collection = Collection [GameTree] deriving Show | |
data GameTree = GameTree { seq::Sequence, subtrees::[GameTree] } deriving Show |
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 Codec.BMP | |
import Data.Word (Word8) | |
import Data.ByteString (pack) | |
pixcelToFlatByteString height width px = pack $ rep height $ rep width px | |
where rep n = concat . replicate n | |
pixcelToPackedRGBA height width px = | |
packRGBA32ToBMP width height $ pixcelToFlatByteString height width px |
OlderNewer