Skip to content

Instantly share code, notes, and snippets.

Chris Lewis chrislewis

Block or report user

Report or block chrislewis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View meetup_message_oauth_example.php
<?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.
*
View MapIsFold.scala
/*
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 Aug 29, 2015
Not so sealed
View Foo.scala
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 Mar 13, 2014
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.
View Lambda255.java
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 Dec 29, 2012
A Reader Either monad transformer for java.util.Properties with Scalaz7
View gist:4409778
/*
* 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 Oct 12, 2012
Andrew's market-making bot in perl
View market_maker.pl
#!/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 Aug 21, 2012
reader monad for java.util.Properties example
View gist:3416494
/* 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")
View gist:2919454
package com.example.foobie
import unfiltered.jetty.Http
import unfiltered.response._
import unfiltered.request._
trait Resolver[A] {
type B
}
@chrislewis
chrislewis / comprehensible.scala
Created Mar 11, 2012
general type and implicit conversion to add support for using a general Bind instance in a for comprehension
View comprehensible.scala
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]
@chrislewis
chrislewis / interpreter.scala
Created Mar 10, 2012
quick interpreter for nescala
View interpreter.scala
package necsala.embedded
import scala.tools.nsc.interpreter.AbstractFileClassLoader
import scala.tools.nsc.{Global, Settings}
import scala.tools.nsc.util.BatchSourceFile
import scala.tools.nsc.io.{AbstractFile, VirtualDirectory}
import java.io.File
import java.util.jar.JarFile
import java.net.URLClassLoader
You can’t perform that action at this time.