Skip to content

Instantly share code, notes, and snippets.

View canpeter's full-sized avatar

Peter canpeter

  • New York City
View GitHub Profile
@canpeter
canpeter / lisp.lua
Last active September 15, 2015 16:01 — forked from polymeris/lisp.lua
Toy Lisp interpreter in Lua / LPEG
local lpeg = require'lpeg'
local P, R, S = lpeg.P, lpeg.R, lpeg.S --patterns
local C, Ct = lpeg.C, lpeg.Ct --capture
local V = lpeg.V --variable
local parser = P {
'program', -- initial rule
program = Ct(V'sexpr' ^ 0),
wspace = S' \n\r\t' ^ 0,
atom = V'boolean' + V'integer' + V'string' + V'symbol',
-- OAuth Request 生成
oauthRequest :: OAuth -> String -> String -> [Parameter] -> IO String
oauthRequest oauth url token parameter = do
timestamp <- show . (\(TOD i _) -> i) <$> getClockTime -- タイムスタンプ取得
nonce <- show <$> randomRIO (0, maxBound::Int) -- 乱数取得
let authorizationParameters_ = parameter ++ [
("oauth_consumer_key", consumerKey oauth),
("oauth_nonce", nonce),
("oauth_timestamp", timestamp),
("oauth_signature_method", "HMAC-SHA1"),
// Make Optional a monad
extension Optional {
// Scala style, define `flatMap` directly
func flatMap<U>(f: (a: T) -> Optional<U>) -> Optional<U> {
switch (self) {
case .None: return nil
case .Some(let value): return f(a: value)
}
}
@canpeter
canpeter / maybe.m
Last active August 29, 2015 14:20 — forked from jmont/maybe.m
// Swift Monads -- Maybe
// Juan C. Montemayor (@norsemelon)
// This operator can be used to chain Optional types like so:
// optionalVal >>= f1 >>= f2
// where f1 and f2 have type `Any -> Any?`
//
// If a value is ever nil, the chain short-circuits and will result in nil.
// This is a much neater way to do this than using the if syntax specified in
// the Swift iBook.
curl -X PUT "https://api.cancapital.com/pq/:application_id/options/:option_id" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $HASH" \
-m 30 \
-v \
# Empty 200 response on success
curl -X GET "https://api.cancapital.com/status/:application_id" \
-H "Authorization: Basic $HASH" \
-H "Content-Type: application/json" \
-m 30 \
-v \
@canpeter
canpeter / post_pq
Last active August 29, 2015 14:03 — forked from ccalloway/post_pq
curl -X POST "https://api.cancapital.com/pq" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $HASH" \
-m 30 \
-d '
{
"can_auth_to_pull_credit": true,
"can": {
"partner_id": 1,
"products": [
curl -i -X POST "http://canconnect-sandbox.herokuapp.com/iq" \
-H "ACCEPT: application/json" \
-H "CONTENT_TYPE: application/json" \
-H "Authorization: Basic $HASH" \
-m 30 \
-d '
{
"operationPurpose" : "expansion",
"requestedAmount" : 100000,
"creditScoreLowerBound" : 750,