Skip to content

Instantly share code, notes, and snippets.

<?php
/*
* This is a simple example of using PHP's OAuth extension to fetch a valid
* token for a given member. The process is a typical OAuth 1.0a flow, which
* includes requesting a member's authorization to act on her behalf and then
* fetching the actual token once authorized. This token can then be stored
* and used to make API calls on the member's behalf. For an example of making
* such a call once you have retriefed an authorized token, see:
*
<?php
/*
* This is a simple example of using PHP's OAuth extension to send a message
* to another member. It assumes you have already recieved the necessary
* authorization from the user and stored the token for reuse.
* See https://gist.github.com/chrislewis/7a1286924a93b369de86 for an
* example of how to fetch a valid token for a given member, with her
* authorization, using your consumer key and secret.
*
/*
CanBuildFrom is easily abused such that the ubiquitous higher order function
map can be repurposed as fold. This is not good; this example demonstrates
a design flaw, not a strength.
*/
import scala.language.postfixOps
import scala.collection.generic
@chrislewis
chrislewis / Foo.scala
Last active August 29, 2015 14:02
Not so sealed
sealed trait Foo
case class Bar(x: Int) extends Foo
case class Baz(name: String) extends Foo
object Foo {
def show(f: Foo) =
f match {
case Bar(x) => x.toString // Quux, a subtype of Bar in a different file, will be matched as a Bar
case Baz(name) => name
}
@chrislewis
chrislewis / Lambda255.java
Created March 13, 2014 01:26
Testing parameter limits of java 8 lambdas. 255 turns out to be the limit for both the number of type parameters and arguments in lambda expressions.
class Lambda255 {
interface F255<A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,GG,HH,II,JJ,KK,LL,MM,NN,OO,PP,QQ,RR,SS,TT,UU,VV,WW,XX,YY,ZZ,AAA,BBB,CCC,DDD,EEE,FFF,GGG,HHH,III,JJJ,KKK,LLL,MMM,NNN,OOO,PPP,QQQ,RRR,SSS,TTT,UUU,VVV,WWW,XXX,YYY,ZZZ,AAAA,BBBB,CCCC,DDDD,EEEE,FFFF,GGGG,HHHH,IIII,JJJJ,KKKK,LLLL,MMMM,NNNN,OOOO,PPPP,QQQQ,RRRR,SSSS,TTTT,UUUU,VVVV,WWWW,XXXX,YYYY,ZZZZ,AAAAA,BBBBB,CCCCC,DDDDD,EEEEE,FFFFF,GGGGG,HHHHH,IIIII,JJJJJ,KKKKK,LLLLL,MMMMM,NNNNN,OOOOO,PPPPP,QQQQQ,RRRRR,SSSSS,TTTTT,UUUUU,VVVVV,WWWWW,XXXXX,YYYYY,ZZZZZ,AAAAAA,BBBBBB,CCCCCC,DDDDDD,EEEEEE,FFFFFF,GGGGGG,HHHHHH,IIIIII,JJJJJJ,KKKKKK,LLLLLL,MMMMMM,NNNNNN,OOOOOO,PPPPPP,QQQQQQ,RRRRRR,SSSSSS,TTTTTT,UUUUUU,VVVVVV,WWWWWW,XXXXXX,YYYYYY,ZZZZZZ,AAAAAAA,BBBBBBB,CCCCCCC,DDDDDDD,EEEEEEE,FFFFFFF,GGGGGGG,HHHHHHH,IIIIIII,JJJJJJJ,KKKKKKK,LLLLLLL,MMMMMMM,NNNNNNN,OOOOOOO,PPPPPPP,QQQQQQQ,RRRRRRR,SSSSSSS,TTTTTTT,UUUUUUU,VVVVVVV,WWWWWWW,XXXXXXX,YYYYYYY,ZZZZZZZ,AAAAAAAA,BBBBBBBB,CCCCCCCC,DDDDDDDD,EEEEEEEE,FFFFFFFF,GGGGGGGG,HHHHHHHH,IIIIIII
@chrislewis
chrislewis / gist:4409778
Created December 29, 2012 22:45
A Reader Either monad transformer for java.util.Properties with Scalaz7
/*
* This is a rendition of https://gist.github.com/3416494. Scalaz7 provides the
* Reader and we take it a step further by constructing and using a Reader Either
* monad transformer with pure error handling, instead of the original impure Reader
* monad that would throw exceptions on parse errors.
*/
import scalaz._
import Scalaz._
import java.util.Properties
@chrislewis
chrislewis / market_maker.pl
Created October 12, 2012 20:11
Andrew's market-making bot in perl
#!/usr/bin/perl
use JSON;
use IO::Socket;
my $pid=$$;
my $user = "marketmaker";
my $pass = "liquidity";
my $host = "10.10.9.115";
my $port = "10000";
@chrislewis
chrislewis / gist:3416494
Created August 21, 2012 15:22
reader monad for java.util.Properties example
/* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */
val dbReader: Reader[Properties, JdbcExecutor] =
for {
driver <- read[String]("db.driver")
uri <- read[String]("db.uri")
user <- read[String]("db.username")
password <- read[String]("db.password")
name <- read[String]("db.pool.name")
minCons <- read[Int]("db.pool.minConnections")
package com.example.foobie
import unfiltered.jetty.Http
import unfiltered.response._
import unfiltered.request._
trait Resolver[A] {
type B
}
@chrislewis
chrislewis / comprehensible.scala
Created March 11, 2012 23:32
general type and implicit conversion to add support for using a general Bind instance in a for comprehension
trait Bind[M[_]] {
def fmap[A, B](ma: M[A], f: A => B): M[B]
def bind[A, B](ma: M[A], f: A => M[B]): M[B]
}
trait Monad[M[_]] extends Bind[M]{
def unit[A](a: => A): M[A]