Skip to content

Instantly share code, notes, and snippets.

View bluescreen303's full-sized avatar

Mathijs Kwik bluescreen303

  • Uithoorn, Netherlands
View GitHub Profile
@bluescreen303
bluescreen303 / config.nix
Created January 12, 2012 22:47
~/.nixpkgs/config.nix
{
packageOverrides = pkgs:
let
haskell = pkgs.haskellPackages_ghc704;
hiPrio = pkgs.lib.hiPrio;
in
rec {
mathijs = pkgs.buildEnv {
name = "mathijs";
@bluescreen303
bluescreen303 / Chapter11.hs
Created October 24, 2011 20:26
Walking a maze breadth first
module Chapter11 where
import Data.List (find, transpose)
data Maze = Maze String [Maze]
unsafeFind :: (a -> Bool) -> [a] -> a
unsafeFind p xs = let Just x = find p xs
in x
@bluescreen303
bluescreen303 / mongrel2-headers.conf.py
Created August 15, 2011 19:30
sample (mockup) mongrel2 config for "headers" filter
add_x_forwarded_proto = Filter(name="/usr/lib/mongrel2/filters/headers.so", settings={
"operation": "set", # set / unset / setIfNull
"name": "x-forwarded-proto",
"value": "https" # it might be nice to have this available as variable "$proto"
})
main = Server(
...
filters = [add_x_forwarded_proto]
)
@bluescreen303
bluescreen303 / double-confirm.js
Created August 14, 2011 22:17
node-mongodb-native double confirmation (untested! :)
Db.prototype.checkoutRawConnection = function() {
var conn = this.serverConfig.checkoutWriter();
return conn.pool[conn.poolIndex++ % conn.pool.length];
};
Db.prototype.lastErrorOnConnection(connection, options, callback) {
if ('function' === typeof options) callback = options, options = {};
var command = DbCommand.createGetLastErrorCommand(options, this);
@bluescreen303
bluescreen303 / wschat-fix.patch
Created August 13, 2011 21:32
small bugfix for wschat example in mongrel2 (dev branch)
diff --git a/examples/wschat/chat.py b/examples/wschat/chat.py
index 4054942..be0b9ab 100644
--- a/examples/wschat/chat.py
+++ b/examples/wschat/chat.py
@@ -110,7 +110,8 @@ while True:
continue
if data["type"] == "join":
- conn.deliver_json(req.sender, users.keys(), data)
+ if len(users.keys()) > 0:
@bluescreen303
bluescreen303 / gist:974811
Created May 16, 2011 16:42
node http proxy - fix for websockets?
diff -urN http-proxy/lib/node-http-proxy.js http-proxy-fixes/lib/node-http-proxy.js
--- http-proxy/lib/node-http-proxy.js 2011-05-16 18:23:58.746129001 +0200
+++ http-proxy-fixes/lib/node-http-proxy.js 2011-05-16 18:37:53.876129001 +0200
@@ -585,10 +585,6 @@
var agent = _getAgent(options.host, options.port),
remoteHost = options.host + (options.port - 80 === 0 ? '' : ':' + options.port);
- // Change headers
- req.headers.host = remoteHost;
- req.headers.origin = 'http://' + options.host;
module Main where
import Control.Distributed.STM.DSTM
import System.Environment (getArgs)
main = startDist goTasks
goTasks = do
(arg:_) <- getArgs
let n = read arg
module Main where
import Control.Distributed.STM.DSTM
import System.Environment (getArgs)
main = startDist goTasks
goTasks = do
(arg:_) ← getArgs
let n = read arg
{-# LANGUAGE OverloadedStrings #-}
import Database.MongoDB
import Data.UString (u)
import Control.Monad.Trans (liftIO)
main = do
ee <- runNet $ do
conn <- connect (host "127.0.0.1")
runConn run conn
module Main where
partEither list = helper list ([],[])
where
helper [] (l,r) = (reverse l,reverse r)
helper ((Left a):xs) (l,r) = helper xs (a:l,r)
helper ((Right b):xs) (l,r) = helper xs (l,b:r)
test = iterate (\(Left x) -> Left (x+1)) (Left 0)