ubuntu 12.04 14.04
Reference http://stackoverflow.com/a/18490935/2037928
Login as root
Install needed packages
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev| echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
| . ~/.bashrc | |
| mkdir ~/local | |
| mkdir ~/node-latest-install | |
| cd ~/node-latest-install | |
| curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 | |
| ./configure --prefix=~/local | |
| make install # ok, fine, this step probably takes more than 30 seconds... | |
| curl https://www.npmjs.org/install.sh | sh |
| /** | |
| * Takes a camel cased identifier name and returns an underscore separated | |
| * name | |
| * | |
| * Example: | |
| * camelToUnderscores("thisIsA1Test") == "this_is_a_1_test" | |
| */ | |
| def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
| "_" + m.group(0).toLowerCase() | |
| }) |
| #!/bin/bash | |
| while : | |
| do | |
| clear | |
| git --no-pager log --graph --pretty=oneline --abbrev-commit --decorate --all $* | |
| sleep 1 | |
| done |
| <project name="migrations"> | |
| <target name="prefix-new-migrations"> | |
| <foreach target="rename-file" param="the-file"> | |
| <path> | |
| <!-- The hardcoded directory containing the migrations --> | |
| <fileset dir="./src/db/migrations" casesensitive="no" includes="*.sql"> | |
| <!-- Exclude any migration files which have already been prefixed --> | |
| <not> | |
| <filename regex="\d+__.*" casesensitive="true"/> |
| package java8tests ; | |
| import java.util.function.BiFunction ; | |
| import java.util.function.Function ; | |
| public class Currying { | |
| public void currying() { | |
| // Create a function that adds 2 integers | |
| BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ; |
ubuntu 12.04 14.04
Reference http://stackoverflow.com/a/18490935/2037928
Login as root
Install needed packages
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev| object MySorts extends Ordering.ExtraImplicits { | |
| def mergeSort[T : Ordering](elems: List[T]): List[T] = elems match { | |
| case Nil | _::Nil => elems | |
| case that => | |
| type L = List[T] | |
| def merge(l1: L, l2: L, acc: L): L = l1 -> l2 match { | |
| case (a::as, b::_) if a < b => merge(as, l2, a::acc) | |
| case (_, b::bs) => merge(l1, bs, b::acc) | |
| case (a::as, _) => merge(as, l2, a::acc) |
The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.
Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.
For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.
Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob
| sbt> eval new scala.sys.SystemProperties().foreach(x => println(x)) | |
| sbt> eval scala.sys.env.foreach(x => println(x)) |
| //EXAMPLE evolution.scala | |
| import java.io.{File, FilenameFilter} | |
| import com.datastax.driver.core.Session | |
| import org.apache.commons.io.filefilter.SuffixFileFilter | |
| import org.joda.time.{DateTime, DateTimeZone} | |
| import play.api.Play.current | |
| import play.api.{Logger, Play} |