This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns balance-check.core) | |
(defn balanced? [s] | |
(-> (reduce (fn [[h & r :as stack] c] | |
(case c | |
\( (conj stack 42) | |
\) (if (= h 42) | |
r | |
(conj stack "unbalanced")) | |
stack)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; inspired by suggestion in THE doc: http://java.ociweb.com/mark/clojure/article.html | |
(ns bootcamp.multi-method) | |
(defn measure-it [size] | |
(cond | |
(< size 3) :small | |
(< size 6) :medium | |
(< size 12) :large | |
:else :hard-to-measure )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns bootcamp.factorial) | |
(defn fast-factorial [number] | |
(loop [n number factorial 1] | |
(if (zero? n) | |
factorial | |
(recur (- n 1) (* factorial n))))) | |
(defn fast-no-loop-factorial | |
([number] (fast-no-loop-factorial number 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
r = redis.StrictRedis(host='localhost', port=6379, db=0) | |
r.zadd('votes:east', **{'riak': 1, 'couchdb': 1, 'cassandra': 1}) | |
r.zadd('votes:north', **{'redis': 1, 'onetick': 1, 'couchdb': 1}) | |
r.zadd('votes:west', **{'redis': 1, 'riak': 1, 'couchdb': 1}) | |
r.zadd('votes:south', **{'voltdb': 1, 'mongodb': 1, 'hazelcast': 1}) | |
r.zadd('votes:north:east', **{'hazelcast': 1, 'riak': 1, 'redis': 1}) | |
r.zadd('votes:north:west', **{'redis': 1, 'cassandra': 1, 'onetick': 1}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.nosqlrep.insert( { _id : 1, votes : ['riak', 'couchdb', 'cassandra'] } ); | |
db.nosqlrep.insert( { _id : 2, votes : ['redis', 'onetick', 'couchdb'] } ); | |
db.nosqlrep.insert( { _id : 3, votes : ['redis', 'riak', 'couchdb'] } ); | |
db.nosqlrep.insert( { _id : 4, votes : ['voltdb', 'mongodb', 'hazelcast'] } ); | |
db.nosqlrep.insert( { _id : 5, votes : ['hazelcast', 'riak', 'redis'] } ); | |
db.nosqlrep.insert( { _id : 6, votes : ['redis', 'cassandra', 'onetick'] } ); | |
db.nosqlrep.insert( { _id : 7, votes : [] } ); | |
print( "\ncommunity votes" ) | |
print( "---------------" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
@Require( { it ==~ /[a-z A-Z]*/ } ) | |
String name | |
@Require( { it in (0..130) } ) | |
int age | |
} | |
def validator = new Validator() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFLAGS=-Wall -g | |
all: clean | |
make ccheck | |
clean: | |
rm -f ccheck | |
rm -rf ccheck.dSYM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.typesafe.training.scalatrain | |
import org.specs2.mutable._ | |
class TrainSpec extends Specification { | |
val kharkovStation = Station("Харьков") | |
val sfStation = Station("Сан Франциско") | |
val parisStation = Station("Париж") | |
val t1 = Time(11, 11) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stopsAt(station: Station) = { | |
for { | |
train <- trainsAt( station ) | |
schedule <- train.schedule.filter(_._2 == station) | |
} yield (schedule._1, train) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> trait Maker { def make: String } | |
defined trait Maker | |
scala> trait HumanMaker extends Maker { def make = "Human" } | |
defined trait HumanMaker | |
scala> trait LoveMaker extends Maker { override def make = "Love" } | |
defined trait LoveMaker | |
scala> class Human extends HumanMaker with LoveMaker |
OlderNewer