This file contains 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
val f0 = (g0:Int=>Int, x:Int) => g0(x) | |
val h0 = ( x:Int ) => f0( p=>p+1, x ) | |
println( "41 + 1 = " + h0(41) ) | |
/******************************************************************************/ | |
/******************************************************************************/ |
This file contains 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 java.net.URL | |
import java.io.File | |
import javax.imageio.ImageIO | |
//lazy val file = new File( "/tmp/testing" ) | |
lazy val file = new URL( "http://goo.gl/vOYtrv" ) | |
lazy val img = ImageIO.read( file ) | |
lazy val width = img.getWidth | |
lazy val height = img.getHeight |
This file contains 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 dimRefs = ( 160, 190 ) | |
def deleteFile( name:String ) = new File(name).delete | |
def createImage( name:String ):BufferedImage = name match { | |
case n if n startsWith "http://" => ImageIO.read( new URL (name) ) | |
case n if n startsWith "https://" => ImageIO.read( new URL (name) ) | |
case _ => ImageIO.read( new File(name) ) | |
} |
This file contains 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 LeetCrypt | |
{ | |
implicit class Encrypt( src:String ) | |
{ | |
def leetOfString( s:String ) = { | |
s.map( | |
c => c match { | |
case 'a' | 'A' => '4' | |
case 'b' => '6' | |
case 'B' => '8' |
This file contains 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 infiniteArg( arg:Any* ) = arg.foreach( println ) | |
infiniteArg( 1, 2, 3 ) | |
infiniteArg( "1", 2, '3' ) |
This file contains 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 scala.io.Source | |
import scala.util.parsing.json._ | |
object Main | |
{ | |
/* | |
** FLICKR SPECIFIC FUNCTIONS | |
*/ | |
def getFlickrInfosJson( content:String ) = { | |
val rawJson = content.split("\n") |
This file contains 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 scala.language.implicitConversions | |
case class Node(nodeVal:Any, left:Option[Node] = None, right:Option[Node] = None) | |
{ | |
def preorder(f:Node => Unit) { | |
f( this ) | |
left.map( _ preorder f ) | |
right.map( _ preorder f ) | |
} | |
} |
This file contains 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 java.util.{Random, Scanner} | |
// | |
// ScalaCorrection.scala | |
// ScalaCorrection | |
// | |
// Created by Remus32 on 20/09/15. | |
// Copyright (c) 2015 Remus32, and rbobillo(revision). All rights reserved. | |
object ScalaCorrection{ |
This file contains 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 factorial(n:Int):BigInt = ((1 to n) :\ BigInt(1))(_ * _) | |
// (1 to n).foldLeft(BigInt(1))(_ * _) | |
def recFactorial(n:Int):BigInt = if (n < 2) n else n * recFactorial(n-1) | |
def tailRecFactorial(n:Int):BigInt = { | |
def fac(n:Int, acc:BigInt):BigInt = n match { | |
case 1 => acc | |
case _ => fac(n-1, n*acc) | |
} |
This file contains 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 TeslaTechQuestion { | |
case class Coord(x:Float, y:Float) // use case class, rather than Tuple | |
val A = Coord(487,143) // shema: B | |
val B = Coord(720,384) // A | |
val C = Coord(839,-235) // C | |
def gradient(a:Coord, b:Coord) = (b.y - a.y) / (b.x - a.x) // calculate 'a' | |
def intersec(a:Coord, b:Coord) = a.y - gradient(a,b) * a.x // calculate 'b' | |
def getCoord(a:Coord, b:Coord, x:Float) = (gradient(a,b) * x + intersec(a,b)) // calculate 'ax + b' |