Skip to content

Instantly share code, notes, and snippets.

@ikenna
ikenna / .sbtrc
Created February 5, 2014 10:57
.sbtrc
alias g=gen-idea
alias r=reload
alias u=update
alias t=test
alias st = ;container:stop; container:start;
@ikenna
ikenna / specs.scala
Last active August 29, 2015 13:56 — forked from teamon/specs.scala
// === Basics
a must beMatching(bar)
a must be matching(bar)
a must not be matching(bar) // negation
// === Any object
a must_== b
a must_!= b
@ikenna
ikenna / gist:10466022
Created April 11, 2014 12:49
Fixing intellij Scala formatting for functions curly braces
Luckily this is easy to fix. From IntelliJ's settings, find the following:
settings -> code style -> Scala -> Wrapping and braces
in "Anonymous method definition"
uncheck "parameters on new line"
@ikenna
ikenna / Write to a file in Scala
Created January 14, 2015 13:19
Write to a file in Scala
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
val p = new java.io.PrintWriter(f)
try { op(p) } finally { p.close() }
}
//Usage
printToFile(new File("fileName.txt"))(p => p.write("someString"))
@ikenna
ikenna / RandomAscii.scala
Last active September 7, 2015 11:38
random ascii string generator in Scala
// random ascii string generator in Scala
def randomString(length: Int) = List.fill(length)(Random.nextPrintableChar).foldRight("")((nextChar, ref) => ref + nextChar)
print(randomString(10))
@ikenna
ikenna / gist:5706366
Created June 4, 2013 14:30
Informix "select 1 from dual "
select 1 from systables where tabid = 1
@ikenna
ikenna / MyFunctionalTest.scala
Created November 6, 2013 12:37
Functional test in Scala Play Framework 2.2 using ScalaTest
package net.ikenna
import play.api.test.Helpers.running
import play.api.test.{FakeApplication, TestServer}
import org.scalatest.FunSuite
import play.api.libs.ws.{Response, WS}
class MyFunctionalTest extends FunSuite {
import scala.concurrent.{Future, Await}
@ikenna
ikenna / clean_code.md
Created July 22, 2017 09:49 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
Tue Apr 7 19:37:54 UTC 2020