Skip to content

Instantly share code, notes, and snippets.

In this gist we will first show that we can beat the arc challenge
(http://www.paulgraham.com/arcchallenge.html), and then build the library that
shows how we did it. This gist is Literate Haskell and is of course executable. The packages needed are happstack-server and applicative-extras, installable using cabal.
Let's start with some imports (for now, you can ignore these)
> {-# LANGUAGE GADTs, TypeSynonymInstances #-}
> module ArcChallenge where
>
> import Control.Applicative
@miikka
miikka / Simple.hs
Created August 24, 2010 19:07
Simple Haskell Twitter OAuth example
{-# LANGUAGE PackageImports #-}
{-
You need to register your Twitter application at <http://dev.twitter.com/>
to get the consumer key and secret needed for OAuth. When connecting to
Twitter for the first time, do this:
let consumer = Consumer "consumer key" "consumer secret"
token <- authenticate
@rodbegbie
rodbegbie / foursquare-v2-oauth-python.py
Created January 18, 2011 23:10
Foursquare v2 API python oauth2 example
### Note: This depends on my fork of a fork of python-oauth2
### https://github.com/offlinelabs/python-oauth2
### (The original python-oauth2 doesn't support OAuth 2.0. It's just the second
### OAuth 1.0 library. dgouldin created a fork which has the Client2 class, and
### I tweaked it to support the latest draft of the OAuth 2.0 spec, as implemented
### by the Foursquare v2 API.)
>>> from django.conf import settings
>>> import oauth2, json
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@joelambert
joelambert / README
Created June 1, 2011 11:03
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php
@qzchenwl
qzchenwl / gist:1129088
Created August 6, 2011 06:41
Eight queens puzzle
import Data.List
isUnique :: (Ord a) => [a] -> Bool
isUnique = all (null . drop 1) . group . sort
cols = [0..7]
solutions = [vec | vec <- permutations cols
, isUnique [vec!!i + i | i <- cols]
, isUnique [vec!!i - i | i <- cols]]
@qzchenwl
qzchenwl / gist:1136647
Created August 10, 2011 11:57
最大质因子
getD n = getD' n 2 where
getD' n factor | n == factor = factor
| n `mod` factor == 0 = getD' (n `div` factor) factor
| otherwise = getD' n (succ factor)
@nicerobot
nicerobot / chrome-cookies.sh
Created December 7, 2011 16:59
Convert Google Chrome sqlite Cookies into cookies.txt. Useful for utilities like curl.
sqlite3 -separator ' ' ${COOKIES:-Cookies} \
'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies'
@leino
leino / glinv.hs
Created January 19, 2012 10:08
Slight extension of http://blog.sigfpe.com/2011/10/quick-and-dirty-reinversion-of-control.html, which adds input capabilities
{--
This file is a slight extension of Sigfpe's "Quick and dirty reinversion of control":
http://blog.sigfpe.com/2011/10/quick-and-dirty-reinversion-of-control.html
I only added input capabilities: yieldInput + modification to yield
and of course the lines in imperative (i.e. our re-captured "main loop") which have to do with getting input.
--}
@qzchenwl
qzchenwl / simple-schema.hs
Created February 26, 2012 10:42
implement sub schema in haskell
{-# LANGUAGE ExistentialQuantification #-}
module Main where
import Debug.Trace(traceShow)
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
import Control.Applicative ((<$>))
import Control.Monad.Error
import Data.IORef
import IO hiding (try)