Skip to content

Instantly share code, notes, and snippets.

View derdewey's full-sized avatar

Xavier Lange derdewey

  • tureus
  • Encinitas, CA
View GitHub Profile
@derdewey
derdewey / Solution
Created April 14, 2011 05:36
Palindrome Checker
maximum [x*y |x <- [100..999], y <- [100..999], isPalindrome (x*y)]
@derdewey
derdewey / pop_goes_the_weasel
Created April 13, 2011 06:56
Project Euler Problem 3 Solution
weasel> let x = Debug.Trace.trace "hi" True
weasel> x
hi
True
weasel> x
True
weasel>
@derdewey
derdewey / gist:916927
Created April 13, 2011 03:48
another non-working way of listing factors in haskell
import Debug.Trace
isMultiple :: (Integral a) => a -> a -> Bool
isMultiple divisor number
| divisor > number = False
| otherwise = (number `mod` divisor) == 0
l_factors :: (Integral a) => a -> a -> [a] -> [a]
l_factors _ 1 list = list
@derdewey
derdewey / code
Created April 12, 2011 07:13
A non-working way of listing factors in haskell
isDivisor :: (Integral a) => a -> a -> b
isDivisor number divisor = ((number `mod` divisor) == 0)
l_factors :: (Integral a) => a -> a -> [a] -> [a]
l_factors 1 target list = list
l_factors divisor target list
| isDivisor target divisor = (l_factors divisor-1 target/divisor divisor:list)
| otherwise = (l_factors divisor-1 target divisor:list)
@derdewey
derdewey / Log of a bad request
Created February 10, 2011 19:58
Per the lists recommendation, this workaround looks for the two WS headers and works around the lack of content-length.
DEBUG src/connection.c:656: parsing
'GET /wsstream HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:6767
Origin: http://localhost:6767
Sec-WebSocket-Key1: m 4 115S8 g8if m aLD T8 yd124
Sec-WebSocket-Key2: 9 %F8 s]6129' ^ 3 C 76
t�C"���`'
@derdewey
derdewey / gist:787004
Created January 19, 2011 22:19
Mongrel2 debugging
Done from a fresh reboot of the mongrel2 server.
#========================= TRY 1 WORKS =======================
#MONGREL2 SERER SESSION
shows nothing... it's happy
# HANDLER SESSION
xavierlange@pelorus:~/code/mongrel2/handler$ make && ./mongrel_handler
gcc -lzmq -ljson mongrel_handler.o bstrlib.o bstraux.o -o mongrel_handler
======NETSTRING======
@derdewey
derdewey / How to close a mongrel2 session in C
Created January 17, 2011 18:20
How to close a mongrel2 connection
# cURL to test mongrel2 handler
me@pelorus:~/code/dds_mongrel2/deployment$ curl localhost:6767 -v
* About to connect() to localhost port 6767 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 6767 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost:6767
> Accept: */*
>
@derdewey
derdewey / Debian Packages.gz Treetop Grammar
Created November 9, 2010 23:38
Spits out tag/value pairs inside of package_list > package trees
grammar Debian
rule package_list
(package "\n"?)+
end
rule package
(tag / value)+ <DebianSyntaxNode::Package>
end
rule tag
tag_value tag_stop
end
Package: acct
Priority: optional
Section: admin
Installed-Size: 352
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Mathieu Trudel <mathieu.tl@gmail.com>
Architecture: i386
Version: 6.5.4-2ubuntu1
Depends: dpkg (>= 1.15.4) | install-info, libc6 (>= 2.4)
Filename: pool/main/a/acct/acct_6.5.4-2ubuntu1_i386.deb
@derdewey
derdewey / Debian Treetop
Created November 9, 2010 00:48
Parse debian Packages.gz
grammar Debian
rule collection
entry+
end
rule entry
(tag space value)
end
rule package_details
tag value &[^$]