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
| require "benchmark" | |
| class Array | |
| def duplicates_reject_uniq | |
| reject { |e| count(e) <= 1 }.uniq | |
| end | |
| def duplicates_uniq_reject | |
| uniq.reject { |e| count(e) <= 1 } | |
| end |
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
| (function (win, doc) { | |
| var by = {}, slice = [].slice, type2method = { | |
| id: "getElementById", | |
| className: "getElementsByClassName", | |
| tagName: "getElementsByTagName", | |
| query: "querySelectorAll" | |
| }; | |
| for (var type in type2method) if (type2method[type] in doc) (function (type, method) { | |
| by[type] = method.match(/(?:Elements|All)/) ? function () { |
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
| /* Copied, Pasted and summarized from ps' source code. | |
| You can use sysctl to get other process' argv. | |
| */ | |
| #include <sys/sysctl.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define pid_of(pproc) pproc->kp_proc.p_pid |
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
| class Proc | |
| def on(g) | |
| f = self | |
| -> a, b { f[g[a], g[b]] } | |
| end | |
| end | |
| class Symbol | |
| def to_func | |
| -> this, *args { this.__send__ self, *args } |
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
| instance Fractional Integer where | |
| fromRational x = 0 | |
| instance Fractional Int where | |
| fromRational x = 1 | |
| a :: Int | |
| a = 0 | |
| b :: Fractional a => a |
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 NoMonomorphismRestriction #-} | |
| data N = A | B | C | D | |
| instance Num N where | |
| fromInteger 0 = C | |
| fromInteger 1 = B | |
| A + B = B | |
| A + C = C | |
| A + D = B |
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
| class H | |
| def initialize(hash) @hash = hash end | |
| def method_missing(name, *args) | |
| if name =~ /([^=]+)=$/ | |
| return @hash[$1.intern] = args.first | |
| end | |
| @hash[name] || @hash[name.to_s] | |
| end | |
| end |
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
| -- based on http://okmij.org/ftp/Haskell/de-typechecker.lhs | |
| {-# LANGUAGE IncoherentInstances,UndecidableInstances #-} | |
| data HTrue | |
| data HFalse | |
| instance Show HTrue where show _ = "HTrue" | |
| instance Show HFalse where show _ = "HFalse" |
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 Data.Has | |
| import Control.Applicative | |
| data X = X; data Y = Y; data Z = Z | |
| newtype Point2D = P2 (X :> Int :&: Y :> Int) | |
| deriving (Has (X `Labelled` Int),Has (Y `Labelled` Int)) | |
| getXY :: (Knows X Int p, Knows Y Int p) => p -> (Int,Int) | |
| getXY = liftA2 (,) (prjl X) (prjl Y) |
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
| bf: bf.hs | |
| ghc --make -O2 bf |
NewerOlder