Skip to content

Instantly share code, notes, and snippets.

@nonowarn
nonowarn / send.rb
Created September 1, 2009 12:23
Reified Object#send
class Send
class << self
def method_missing meth, *holes_or_args, &block
do_send = -> args {
-> receiver {
receiver.__send__(meth, *args, &block)
}
}
if holes_or_args.any? { |hoa| hoa == Hole }
-> *args_for_holes {
@nonowarn
nonowarn / r.hs
Created September 5, 2009 14:08
Trace of the paper for reflection in haskell
-- trace of http://www.cs.rutgers.edu/~ccshan/prepose/prepose.pdf
import Foreign
import Foreign.Storable
import Foreign.C.Types
data Zero; data Succ n; data Pred n; data Twice n;
class ReflectNum s where reflectNum :: Num a => s -> a
instance ReflectNum Zero where reflectNum _ = 0
@nonowarn
nonowarn / git-man.sh
Created September 6, 2009 14:44
Git Doc
mkdir manual && cd manual
git init
git fetch-pack git://git.kernel.org/pub/scm/git/git.git man html |
while read a b
do
echo $a >.git/$b
done
cp .git/refs/heads/man .git/refs/heads/master
git checkout
@nonowarn
nonowarn / blogpost.lhs
Created September 6, 2009 13:23
A blog post for Data.Reflection
(This code uses Data.{Reflection,Tagged} which are not in standard
modules, So you need to run "cabal install reflection" to install
them before loading it)
Normally, in LL (Lightweight Languages) such as Ruby or Perl, mocking
is very easy. It means just overwriting a function to be mocked. But I
want to do this in haskell. Every functions are immutable, so I can't
overwrite it.
So, in LL, If overwriting is not apporopriate, as usual, mocked
@nonowarn
nonowarn / definr.sh
Created September 13, 2009 18:41
Definr is Awwwwesome
definr () {
curl http://www.definr.com/definr/show/${1// /+} 2>/dev/null \
| perl -ple 's/&nbsp;/ /g; s/<.+?>//g;'
}
@nonowarn
nonowarn / r.hs
Created September 17, 2009 14:55
Finding repeatings in lists
import Prelude()
import Prelude.Plus
type Repeating = []
findRepeatings :: Eq a => [a] -> [Repeating a]
findRepeatings = concatMap findRepeatingsStartFromHere . tails
findRepeatingsStartFromHere :: Eq a => [a] -> [Repeating a]
findRepeatingsStartFromHere =
@nonowarn
nonowarn / himabot.hs
Created October 3, 2009 14:06
Awful Bot for HIMA
module Main where
import Prelude()
import Prelude.Plus
import Data.Char
import Data.Maybe
import Network.Socket
import qualified Network.IRC as I
import Control.Concurrent
import Data.Time
@nonowarn
nonowarn / alert.js
Created October 13, 2009 18:24
Can be invoked from anywhere
alert("Hello from gist");
@nonowarn
nonowarn / ghc-in-SL.sh
Created October 21, 2009 17:49
Wrapper Script for GHC on SL
#!/bin/sh
exec /Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/ghc -B/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/. -dynload wrapped ${1+"$@"} -optc-m32 -opta-m32 -optl-m32
@nonowarn
nonowarn / applicative-fold.hs
Created November 7, 2009 12:42
Applicative Fold
import Control.Applicative
import Control.Arrow
-- foldr-version of http://squing.blogspot.com/2008/11/beautiful-folding.html
data Fold a c = forall b. Fold (a -> b -> b) b (b -> c)
runFold :: Fold a c -> [a] -> c
runFold (Fold cons nil c) ls = c . foldr cons nil $ ls
both :: Fold a c -> Fold a c' -> Fold a (c,c')