Skip to content

Instantly share code, notes, and snippets.

View seckcoder's full-sized avatar

Wei Li seckcoder

  • Blablabla
  • San Francisco
View GitHub Profile
@tonyg
tonyg / monad.rkt
Last active March 30, 2024 09:05
Monads in Racket
#lang racket/base
;; Monads in Racket, including polymorphic bind, return and fail.
;; Haskell-like do-notation.
(provide define-monad-class
(struct-out monad-class)
monad?
gen:monad
monad->monad-class
determine-monad
@fdelbos
fdelbos / TJSONProtocol.py
Created October 24, 2012 20:35
A Python JSON implementation of the Thrift protocol
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@jneira
jneira / express-sample.cljs
Created August 25, 2011 20:07
Clojurescript / node.js basic examples
(ns express_sample
(:require [cljs.nodejs :as node]))
(def express (node/require "express"))
(def app (. express (createServer)))
(defn -main [& args]
(doto app
(.use (. express (logger)))
(.get "/" (fn [req res]
@ghoseb
ghoseb / gevent_example.py
Created July 27, 2011 09:27
Gevent spawn / link example
from gevent import monkey; monkey.patch_all()
import gevent
import gevent.greenlet
from functools import partial
from random import random
import urllib
import urllib2
def on_exception(fun, greenlet):
import gevent
from thrift.server.TServer import TServer
# XXX Hackish, but should be safe: monkey patch gevent socket support into
# Thrift. Overall I think this is cleaner than reimplementing all of TSocket.
from thrift.transport import TSocket; TSocket.socket = gevent.socket
from thrift.transport.TTransport import TTransportException
class TGEventServer(TServer):
"""Gevent socket server."""
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby