Skip to content

Instantly share code, notes, and snippets.

View leedm777's full-sized avatar

David M. Lee leedm777

View GitHub Profile
object ZzubZzif {
val fizzbuzz: PartialFunction[Int, String] = {
case x if x % 15 == 0 => "fizzbuzz"
case x if x % 5 == 0 => "buzz"
case x if x % 3 == 0 => "fizz"
}
// I'm actually embarrassed that this is the best I can do
def zzubzzif(seq: Seq[String]): Seq[Int] = {
val fizzbuzzIndexed = new PartialFunction[(Int, Int), (String, Int)] {
@leedm777
leedm777 / fib.scala
Created May 7, 2012 19:34
fibonacci sequence, in scala
val fib: Stream[BigInt] = {
def nextFib(a: BigInt, b: BigInt): Stream[BigInt] = {
Stream.cons(a + b, nextFib(b, a + b))
}
Stream.cons(0, Stream.cons(1, nextFib(0, 1)))
}
@leedm777
leedm777 / tap.cpp
Created June 22, 2012 19:42
tap implementation for C++11
/** tap implementation for C++11 */
template<typename T, typename F>
T tap(T &&obj, F const &fn) {
fn(obj);
return obj;
}
// usage
tap(new User(params), [](User *u) {
if (u->isValid()) {
@leedm777
leedm777 / future.scala
Created August 1, 2012 23:06
Snippets for Akka Future's talk
// You've gotta start somewhere
import akka.dispatch.Future
implicit val system = akka.actor.ActorSystem("MySystem")
// lame
val WHY_YOU_TAKE_SO_LONG: Seq[Kitten] =
grep(theWorld, kittens)
// awesome
val allKittens: Future[Seq[Kitten]] =
@leedm777
leedm777 / callback-insanity.js
Created August 2, 2012 02:01
Insanity of callbacks
getSomething(function(thing) {
doSomethingWithIt(thing, function(somethingElse) {
evenSomethingElse(somethingElse, function(inTooDeep) {
// result A
})
})
doSomethingElseWithIt(thing, function(somethingElse) {
// result B
})
whenBothAreDone(thing, A, B) // magic!
@leedm777
leedm777 / imafunction.scala
Created September 13, 2012 19:36
Object can be functions in Scala
scala> object ImaFunction {
| def apply() { println("I am a function") }
| }
defined module ImaFunction
scala> case class Sois(name: String) {
| def apply() { printf("%s is also a function", name) }
| }
defined class Sois
@leedm777
leedm777 / res_hello.c
Created October 19, 2012 18:07
Asterisk's simplest module
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012, Digium, Inc.
*
* David M. Lee, II <dlee@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
@leedm777
leedm777 / app_hello.c
Created October 22, 2012 11:53
Asterisk's simplest application
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012, Digium, Inc.
*
* David M. Lee, II <dlee@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
@leedm777
leedm777 / my-configure.sh
Created March 21, 2013 17:33
My wrapper for Asterisk's configure script
#!/bin/bash
TOPDIR=.
if test $1 && test -d $1; then
TOPDIR=$1
shift
fi
TOPDIR=$(cd ${TOPDIR} && pwd)
This is an attempt to fix some linking problems compiling Digium's fork of PJSIP on OS X.
diff --git a/build/rules.mak b/build/rules.mak
index dc74f52..d5006c7 100644
--- a/build/rules.mak
+++ b/build/rules.mak
@@ -14,6 +14,8 @@ SONAME = $($(APP)_SONAME)
ifeq ($(SHLIB_SUFFIX),so)
SHLIB_OPT := -shared -Wl,-soname,$(SONAME)