Skip to content

Instantly share code, notes, and snippets.

public final class ImmutableDummy {
public final Integer x;
public final Option<Integer> y;
@JsonCreator
public ImmutableDummy(@JsonProperty("x") Integer x,
@JsonProperty("y") Integer y) {
this.x = x;
this.y = Option.apply(y);
@tabdulradi
tabdulradi / rational.js
Last active August 29, 2015 14:14
SICP using JS > rational
function pair(a, b) {
return function(i) {
if (i === 0) return a
else return b
}
}
function head(p) {
return p(0)
}
function tail(p) {
import akka.actor._
class FibonacciGenerator extends Actor {
import FibonacciGenerator._
def receive = fib()
def fib(a: Long = 0, b: Long = 1): Receive = {
case Next =>
val c: Long = a + b
@tabdulradi
tabdulradi / calc.py
Last active December 21, 2015 19:19
Python Using a dict instead of Switch statements
def switch(cases, case, default_case, *args, **kwargs):
return cases.get(case, default_case)(*args, **kwargs)
def power(x):
return x ** 2
def add(x, y):
return x + y
def illegal_operator(*args, **kwargs):
@tabdulradi
tabdulradi / namespace.py
Last active December 10, 2015 10:48
Provides an adapter to allow using a class object in name-spacing your config constants conveniently . It allows you to use the dot notation to refer to your conf/constant, yet you can use features like key-word args unpacking too. It supports name-space inheritance from regular classes.
from collections import Mapping
from itertools import ifilter
class Namespace(Mapping):
'''
Provides an adapter to use a class as dict, and object at the same time.
It allows you to use the dot notation to refer to your conf/constant,
yet you can use features like key-word args unpacking too.