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
@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 / 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
}
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
View meetup_oauth_example.php
<?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:
*
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 bifunctor.scala
import scala.language.higherKinds
trait Bifunctor[BF[_, _]] {
def bimap[A, B, C, D](bf: BF[A, C], fab: A => B, fcd: C => D): BF[B, D]
/* Mapping over one of the sides is convenient and can be implemented easily
in terms of `bimap`. */
/** Map over the "first" side, transforming the type and potentially the value
(if the BF instance is of the "first" type, natrually.) */
View Fλip.scala
object Fλip {
val tParams = (1 to 23).map { i =>
(i + 'A' - 1).toChar
}
def getParams(arity: Int): IndexedSeq[Char] =
(0 to arity).map(tParams(_))
def getTypeSig(seq: IndexedSeq[Char]) =
s"""(${seq.init.mkString(",")}) => ${seq.last}"""
View aws_docker_jenkins.sh
# Zero to Dockerized Jenkins on AWS.
# We use the stock docker image (https://registry.hub.docker.com/_/jenkins/)
# as well as the stock Linux AMI (as of this writing https://aws.amazon.com/amazon-linux-ami/2014.09-release-notes/).
# We also assume you have configured an AWS identity, key pair, a security
# group that allows inbound TCP/8080, and that you have associated these with
# the instance.
sudo yum install docker
sudo service docker start
View aws_docker_nexus.sh
# Zero to Dockerized Nexus on AWS.
# We use the stock nexus image (https://registry.hub.docker.com/u/sonatype/nexus/)
# as well as the stock Linux AMI (as of this writing https://aws.amazon.com/amazon-linux-ami/2014.09-release-notes/).
# We also assume you have configured an AWS identity, key pair, a security
# group that allows inbound TCP/8081, and that you have associated these with
# the instance.
sudo yum install docker
sudo service docker start
View gist:152965
import java.util.{Calendar, Date}
import Calendar._
class TimeIncrement(val increment: Int /* FIXME */, val amount: Int)
class IntDate(val number: Int) {
def days = new TimeIncrement(DATE, number)
}
You can’t perform that action at this time.