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
# ----- cd to OLDPWD @ each new Term session | |
function cd() | |
{ | |
builtin cd $@ | |
pwd > ~/.old_pwd | |
} | |
if [ -f ~/.old_pwd ];then | |
cd `cat ~/.old_pwd` |
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
class Puissance(init:Int) | |
{ | |
private var _maVariable = init | |
def maVariable = _maVariable | |
def maVariable_= (n:Int) { | |
_maVariable = 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
implicit def facto( x:Int ) = new { | |
def ! = (1 to x).foldLeft( BigInt(1) )( _ * _ ) | |
} | |
println( 8! ) //equivaut a un simple appel de methode -> println( 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
import scala.language.reflectiveCalls | |
import scala.language.implicitConversions | |
object MyMath { | |
implicit def doubleOps(x: Double) = new { | |
def **(n:Double):Double = Math.pow( x, n ) | |
def <<<(n:Double):Double = Math.pow( 2, n ) * x | |
} |
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 tolerance = 0.0001 | |
def isCloseEnough( x: Double, y: Double ) = Math.abs( (x - y) / x ) < tolerance | |
def fixedPoint( f: Double => Double )( first: Double ) = { | |
def iterate(guess: Double): Double = { | |
val next = f(guess) | |
if (isCloseEnough( guess, next )) | |
next |
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.postfixOps | |
implicit class factorial(n:Int) { | |
def ! = (1 to n).foldLeft(BigInt(1))(_ * _) | |
} | |
println( (5!) * (5!) ) |
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.io._ | |
object Read | |
{ | |
val out = "dest" | |
val ext = ".out" | |
def main( av:Array[String] ) | |
{ | |
try { |
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.io.File | |
/* | |
* list files in "/" | |
*/ | |
new File("/").listFiles.sortWith( _.toString < _.toString ).map(println) | |
/* | |
* make directory | |
*/ |
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
implicit def manOf[T: Manifest]( t:T ) = new { | |
def getType = manifest[T] | |
} | |
implicit def range( x:Int ) = new { | |
def ->( n:Int ) = (x to n).toList | |
} | |
val list = (1 -> 7) | |
val res = list.mkString("[", ",", "]") |
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._ | |
try | |
{ | |
val datas = fromFile( args(0) ).mkString // file's text to a BIG string | |
.groupBy( x => x ) // group occurrences into strings in a map (Char -> String) | |
.mapValues( _.size ) // converts map (Char -> Int) => where Int is: String.size | |
.toList // map to list (preparing it for sorting) | |
.sortWith( _._2 > _._2 ) // reverse sorting with the 2nd value of each element |
OlderNewer