Skip to content

Instantly share code, notes, and snippets.

@laser
laser / ghci_output.log
Last active August 29, 2015 14:02
cryptic error message
*Cis194.Hw.SExpr> :r
[2 of 2] Compiling Cis194.Hw.SExpr ( src/Cis194/Hw/SExpr.hs, interpreted )
src/Cis194/Hw/SExpr.hs:84:38:
Couldn't match type `SExpr' with `Atom'
Expected type: [SExpr] -> Atom
Actual type: [SExpr] -> SExpr
In the first argument of `pure', namely `(Comb)'
In the first argument of `(<*>)', namely `pure (Comb)'
In the second argument of `(<|>)', namely
@laser
laser / wtf.hs
Created May 30, 2014 23:07
wtf.haskell
-- Ex. 2 - implement an Applicative instance for Parser
--
-- A. pure a represents the parser which consumes no input
-- and successfully returns a result of a.
--
-- B. p1 <*> p2 represents the parser which first runs p1
-- (which will consume some input and produce a
-- function), <----- doesn't this produce a Maybe (a, String) ????
-- ...then passes the remaining input to p2
@laser
laser / div_prime.hs
Created May 25, 2014 00:27
debugging the div' function using guards
import Debug.Trace
div' :: Integer -> Integer -> Integer
div' x y
| trace ("x is: " ++ (show x) ++ " and y is: " ++ (show y)) False = undefined
| otherwise = x `div` y
-- guards are evaluated from top to bottom until a match is found, so we fire off
-- our call to trace (which returns False) and move on to the next guard (which is
-- our real implementation).
#!/usr/bin/env python
import barrister
import urllib2
import sys
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, 'http://localhost:3000/','admin','admin')
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
trans = barrister.HttpTransport("http://localhost:3000/v1/todos", handlers=[auth_handler])
#!/usr/bin/env python
import barrister
import urllib2
import sys
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, 'http://localhost:3000/','admin','admin')
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
trans = barrister.HttpTransport("http://localhost:3000/v1/todos", handlers=[auth_handler])
@laser
laser / transport.js
Last active August 29, 2015 14:01
Custom Transport / Headers - JavaScript (browser)
// initialize the API client
function initApp(callback) {
function transport(req, callback) {
var settings = {
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(req),
beforeSend: function(xhr) {
// set the Authorization header
@laser
laser / server.go
Created May 12, 2014 20:34
Basic Server - Golang
package main
import (
"fmt"
"github.com/coopernurse/barrister-go"
"net/http"
t "./todos"
s "./store"
)
@laser
laser / errors.py
Last active August 29, 2015 14:01
Error Codes - Python
#!/usr/bin/env python
import barrister
from bottle import run, post, request
from store import Store, RecordNotFound, UserDataInvalid, MaxTodosExceeded
from functools import wraps
import sys
def guard(*exceptions):
errors = {
@laser
laser / header.js
Last active August 29, 2015 14:01
Custom Header (Authentication) - JavaScript (browser)
// initialize the API client
function initApp(callback) {
function transport(req, callback) {
var settings = {
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(req),
beforeSend: function(xhr) {
// set the Authorization header
// initialize the API client
function initApp(callback) {
function transport(req, callback) {
var settings = {
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(req),
beforeSend: function(xhr) {
// set the Authorization header