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
// http://stackoverflow.com/a/2257844/4933928 | |
import collection.mutable.Buffer | |
import java.{lang => jl, util => ju} | |
trait ==>>[A, B] extends (A => B) { | |
def apply(a: A): B | |
} | |
object ==>> { |
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
object Main extends App { | |
import scala.reflect._ | |
import scala.reflect.runtime.universe._ | |
def foo[A: TypeTag](x: A) = typeOf[A] match { | |
case t if t <:< typeOf[AnyVal] => println(s"anyval: $x") | |
//case t if t <:< typeOf[AnyRef] => println(s"anyref: $x") | |
case _ => println(s"else: $x") | |
} | |
foo(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
shellPrompt := { state => | |
def textColor(color: Int) = { s"\033[38;5;${color}m" } | |
def backgroundColor(color:Int) = { s"\033[48;5;${color}m" } | |
def reset = { s"\033[0m" } | |
def formatText(str: String)(txtColor: Int, backColor: Int) = { | |
s"${textColor(txtColor)}${backgroundColor(backColor)}${str}${reset}" | |
} | |
val red = 1 | |
val green = 2 |
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
scalaVersion := "2.11.7" | |
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.2.0" | |
libraryDependencies += "com.decodified" %% "scala-ssh" % "0.7.0" |
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
//object Z { | |
object Z extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scalaz.Validation.FlatMap._ | |
def loadCsv(): List[String] = { | |
List("1,me,3,4", "2,he,0,100", "No3,aaaaaaaaaaaaaaaa,1,10") | |
} |
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
module Main where | |
import Control.Monad.Identity | |
import Control.Monad.State | |
import Control.Monad.Writer | |
type Stack = [Int] | |
type WriterStack a = WriterT [String] (StateT Stack Identity) a | |
run :: WriterStack a -> Stack -> ((a, [String]), 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
module FibSlow | |
def self.fib(n) | |
if n <= 1 | |
return n | |
end |
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 main | |
import "fmt" | |
// 2x2 matrix multiplication | |
func mul(a, b [4]int) [4]int { | |
var ret [4]int | |
ret[0] = (a[0]*b[0] + a[1]*b[2]) % 1000 | |
ret[1] = (a[0]*b[1] + a[1]*b[3]) % 1000 | |
ret[2] = (a[2]*b[0] + a[3]*b[2]) % 1000 |
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
#!/usr/bin/env ruby | |
N = 10 ** 8 | |
def exp(a, n) | |
y = if n <= 2 | |
a ** n | |
elsif n.even? | |
x = exp(a, n/2) | |
x * x |
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
numbers = [] | |
while n = gets | |
numbers.push n.to_i | |
end | |
ntimes = 0 | |
sorted = numbers.sort | |
indexes = [] | |
numbers.each_with_index do |n, idx| |