Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
@lobster1234
lobster1234 / pom.xml
Created September 6, 2011 06:34
Maven pom.xml compatible with Scala 2.9.1 with updated dependency versions. This is needed because the archetype:generate for scala-archetype-simple will be 2.8 and the tests will fail with 2.9.1.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.manish</groupId>
<artifactId>scala-simple</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>My wonderfull scala app</description>
<inceptionYear>2010</inceptionYear>
<licenses>
<license>
@debasishg
debasishg / gist:1261857
Created October 4, 2011 14:58
a brief rant about |@| in scalaz
/**
* |@| is a helper function that helps you accumulate applicative functors. It gives you an ApplicativeBuilder (it's part of
* the implementation though) through which you accumulate your applicatives just as you would using the Builder pattern of
* the GoF in the OO world. Once you have all the applicatives you can pass it a function that will be applied to all the
* values that you have accumulated so far. e.g.
*/
scala> (1.some |@| 2.some) apply {_ + _}
res1: Option[Int] = Some(3)
-- A simple definition without using any fancy functions.
haskell>let ifMaybe pred value = if pred value then Just value else Nothing
haskell>:t ifMaybe
ifMaybe :: (a -> Bool) -> a -> Maybe a
haskell>ifMaybe (const True) 2
Just 2
haskell>ifMaybe (const False) 2
Nothing
-- Using functions from standard library.
@angus-c
angus-c / nodeListMixin.js
Created October 12, 2011 19:06
array-like NodeList via mixins
var NodeList = function() {};
var nodeListExtras = {x: 23};
mixin(NodeList.prototype, Array.prototype, nodeListExtras);
function mixin(obj /*, mixins*/) {
var mixins = [].slice.call(arguments, 1);
for (var i=0; i<mixins.length; i++) {
var thisMixin = mixins[i];
var props = Object.getOwnPropertyNames(thisMixin);
for (var j=0; j<props.length; j++) {
@dvanhorn
dvanhorn / Evaluator.java
Created October 28, 2011 02:12
Compositional interpreter for lambda calculus as Visitor in Java for @ccshan @djspiewak @kaleidic
// Compositional evaluator as visitor
import java.math.BigInteger;
// Syntax
interface Exp {
<X> X accept(Visitor<X> v);
}
@rbxbx
rbxbx / 1_oo.rb
Created November 17, 2011 01:48
Bootstrapping a lightweight Object System in Ruby
class Person
def initialize(name, age)
@name = name
@age = age
end
def set_name(new_name)
@name = new_name
end
@frenchy64
frenchy64 / seq_type_annotation.clj
Created December 13, 2011 10:40
seq type annotation
;; Type annotation for seq, inspired by haskell
;; (+T <var> :- <interface/protocol>* => <classes>)
(+T clojure.core/seq :- (ISeq a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (Seqable a) (ISeq b) => a -> b)
(+T clojure.core/seq :- nil -> nil)
(+T clojure.core/seq :- (Iterable a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (PrimArray a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (CharSequence a) (ISeq b) => a -> b)
@mgax
mgax / manage.py
Created January 20, 2012 19:22
Flask application template
#!/usr/bin/env python
import flask
import flaskext.script
default_config = {
}
def create_app():
import views
Object addTrait := method(obj,
resolutions := call evalArgAt(1)
if(resolutions isNil, resolutions = Map clone)
getSlot("obj") foreachSlot(name, value,
if(getSlot("self") hasLocalSlot(name),
if(name == "type", continue)
if(resolutions at(name) isNil, Exception raise("""Slot '#{name}' already exists in #{getSlot("self") type}[#{getSlot("self") uniqueId}]. Give it a new name in the map argument.""" interpolate))
getSlot("self") setSlot(resolutions at(name), getSlot("value"))
continue
@tbroyer
tbroyer / Html5Historian.java
Created February 22, 2012 10:07
GWT PlaceHistoryHandler.Historian using HTML5 pushState and onpopstate
/*
* Copyright 2012 Thomas Broyer <t.broyer@ltgt.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software