Skip to content

Instantly share code, notes, and snippets.

View lucamolteni's full-sized avatar
🏠
Working from home

Luca Molteni lucamolteni

🏠
Working from home
View GitHub Profile
module Simpson where
data Value = Value
{ minRange :: Double
, maxRange :: Double
, dof :: Int
, expectedValue :: Double
} deriving (Eq)
type Error = Double
package it.lm;
public class Main {
public static void main(String[] args) {
B b = new B();
A<B> a = new A<B>(b);
C<A<B>> c = new C<A<B>>(a);
}
public class CategoryTheory {
public static <T> Function<T, T> id() {
return new Function<T, T>() {
@Override
public T apply(T arg) {
return arg;
}
};
}
public class CategoryTheory {
public static <T> Function<T, T> id() {
return new Function<T, T>() {
@Override
public T apply(T arg) {
return arg;
}
};
}
@lucamolteni
lucamolteni / gist:67004d88bf6a1ed88e2e
Last active August 29, 2015 14:11
Ancient vs Modern Programming
http://www.codewars.com/kata/51c8991dee245d7ddf00000e/solutions/javascript
"Complete the solution so that it reverses all of the words within the string passed in."
function reverseWords(str){
//split it into words, store in array
var words = str.split(" ")
var output = "";
//reverse the array and concat each word with space
for(var i = words.length-1; i >= 0; i--){
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
Prova$.main([Ljava/lang/String;)V @0: aload_2
Reason:
Type top (current frame, locals[2]) is not assignable to reference type
Current Frame:
bci: @0
flags: { }
locals: { 'Prova$', '[Ljava/lang/String;' }
[17:06:42] volothamp: simple question: why does this expression evalute to null?
[17:06:44] volothamp: scala> val x: Integer = if (0 != 1) x else 42
[17:06:44] volothamp: x: Integer = null
[17:06:58] darkfrog: hehe
[17:07:14] darkfrog: volothamp: you're declaring x and assigning it x dude
[17:07:59] darkfrog: volothamp: I have no idea what you're trying to do, but you're doing it wrong. :-p
[17:08:10] volothamp: darkfrog: it's an edge case :p
[17:08:17] arjen-jonathan: I think that the compiler is telling you:
[17:08:30] darkfrog: volothamp: it's not an edge case, it's bad code
[17:08:44] TKH (~TKH@p1139-ipbf1009souka.saitama.ocn.ne.jp) joined the channel
Try(jsValue.as[T]).getOrElse(throw BadRequestException("invalid.json")
@lucamolteni
lucamolteni / gist:9be503b1b19577b3cbcc
Created March 18, 2015 10:09
Default value is an exception
Try(jsValue.as[T]).getOrElse(throw BadRequestException("invalid.json")
case class User(name: String, homepageUrl: Option[String])
case class UserProfile(userName: String, profile: String)
def findUser = Future.successful(User("Bob", Some("http://bob.com")))
def downloadProfile(url: String): Future[String] = Future.successful("Profile from the interwebs...")
def profile(user: User): Future[Iterable[String]] = Future.sequence(user.homepageUrl.map(downloadProfile))