Skip to content

Instantly share code, notes, and snippets.

View VoQn's full-sized avatar
:shipit:
I may be slow to respond.

Kazuhiro Mizushima VoQn

:shipit:
I may be slow to respond.
View GitHub Profile
@VoQn
VoQn / alg.rb
Created February 15, 2012 21:16 — forked from mizchi/alg.rb
def qsort (arr, left=0, right=arr.length-1, pl=left, pr=right)
x = arr[(left+right)/2]
begin
pl+=1 while arr[pl] < x
pr-=1 while arr[pr] > x
arr[pl], arr[pr] = arr[pr], arr[pl]
end while arr[pl] != arr[pr]
qsort(arr, left, pl-1) if pl-left > 1
qsort(arr, pr+1, right) if right-pr > 1
end
@VoQn
VoQn / numberliteral-is-liar.hs
Created January 26, 2012 10:17
[0,0.1..1.0] != (map (/ 10) [0..10]) ? ref: http://qiita.com/items/1891
-- Is List Literal with Number liar ?
--
-- ;-)
--
-- This Sample Code Depend on test-framework, and QuickCheck 2
-- try this
-- cabal install test-framework
-- cabal install test-framework-th
-- cabal install test-framework-quickcheck2
-- cabal install QuickCheck
@VoQn
VoQn / oreo.hs
Created January 25, 2012 05:11
オレオしりとりゲーム
module Main ( main ) where
import Control.Applicative ( (<$>) )
import qualified System.Console.ANSI as Console
import qualified Test.QuickCheck as QuickCheck
data ConsoleMode = Battle | Combo | Result deriving ( Eq, Show )
main :: IO a
main = do
@VoQn
VoQn / parser_example.hs
Created January 13, 2012 04:41
Applicative Style Parsec
import Control.Applicative hiding ( (<|>) )
import Text.Parsec
-- parse like ruby's String.strip
escSpace parser = spaces *> parser <* spaces
-- parse like "between" in Text.Parsec
close opener parser closer = char opener *> escSpace parser <* char closer
-- Example
import Data.List ( isInfixOf )
main = print . filter (isInfixOf "AAG") . sequence $ flip replicate "ACGT" 5
@VoQn
VoQn / example.scm
Created January 10, 2012 05:07
TypeSafe CLOS MOP ref: http://qiita.com/items/1632
(define (loop-mod$ max)
(^x ((^v (if (= v (floor v)) (x->integer v) v))
(cond ((<= max x) (fmod x max))
((> 0 x) (fmod (+ x max) max))
(else x)))))
(define (inner$ min max) (cut clamp min <> max))
(define-class* <hsl> (<color>)
((hue :is-a <real> :filter (loop-mod$ 360))
@VoQn
VoQn / sample.css
Created January 10, 2012 03:14
HTML5 + CSS3 Demo : Navigation GUI like iPhone ref: http://qiita.com/items/1630
nav#header-navigation > ul {
padding: 0.4em 0;
background-color: hsl(210, 30%, 60%);
background-image:
-webkit-linear-gradient(
hsl(210, 30%, 70%)
, hsl(210, 30%, 61%) 50%
, hsl(210, 30%, 59%) 50%
, hsl(210, 30%, 50%)
);
@VoQn
VoQn / rgb_to_hex.rb
Created January 6, 2012 11:18
Interactive RGB Color Hex Convert
# Interactive RGB Color Hex Convert
# usage:
# $ ruby rgb_to_hex.rb
# r g b > 255 51 234
# hex: #ff33aa
# r g b > 0
# ### Please type 3 int values: red green blue
# r g b > 132 256 -1
# ### Please type 3 int values: (0 <= x <= 255)
# r g b > quit
this is sample code
-- factorial. n! = 1 * 2 * 3 * ... * ( n - 1)
fact :: Int -> Int = F fact
-- Functor function for factorial
F f x :: (Int -> Int) -> Int -> Int = 1 if 0 `is` x else x * f $ x - 1
-- Instead, functions define without Type Binding.
-- But, it maybe do unexpected work
fact2 = F2 fact2 -- fact2 :: Num a => a -> a
-- dependency: utf8-string
data Character = Azu | Ruizu deriving Eq
instance Show Character where
show c = case c of
Azu -> "あず"
Ruizu -> "ルイズ"
class Mederable a where