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 Generate(charset: List[Char], len: Int) { | |
val SIZE = charset.size | |
val MAXWORDS = math.pow(charset.length, len).toInt | |
val words = bf(0).toList | |
def getIndices : Long => List[Int] = | |
number => (number match { | |
case 0 => Nil | |
case _ => (number % SIZE).toInt :: getIndices(number / SIZE) | |
}).padTo(len, 0) |
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
/////////////////// | |
// // | |
// basic funcs // | |
// // | |
/////////////////// | |
def add1( x:Int ):Int = x + 1 // add1(0) = 1 | |
def add2 : Int => Int = _ + 2 // add2(1) = 3 | |
def add3 : Int => Int = | |
x => x + 3 // add3(3) = 6 |
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.collection.mutable.PriorityQueue | |
val queue = new PriorityQueue[(String, Int)]()(Ordering.by(- _._2)) | |
queue.enqueue("Cube" -> 8) | |
queue.enqueue("Cube" -> 4) | |
queue.enqueue("Cube" -> 5) | |
queue.enqueue("Cube" -> 2) | |
// queue = PriorityQueue((Cube,2), (Cube,4), (Cube,5), (Cube,8)) | |
queue.dequeue |
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' |
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
/* | |
** DOES NOT WORK, because of Scala's conversions | |
*/ | |
import Math.{abs,sin,pow} | |
object MD5 { | |
var INIT_A,a = 0x67452301 | |
var INIT_B,b = 0xEFCDAB89 | |
var INIT_C,c = 0x98BADCFE |
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
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
/* | |
** To bypass SSL, just call | |
** SSLBypasser.bypassSSL | |
** in your main | |
*/ | |
object SSLBypasser | |
{ | |
import java.security.cert.X509Certificate | |
import javax.net.ssl._ |
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 io.Source | |
object Main { | |
def formatInfos( infos:Array[String], password:String ) = { | |
val source = infos | |
.filter( _.contains("0x00000007 <blob>=") ).head.split( "<blob>=" ).last | |
val login = infos | |
.filter( _.contains("\"acct\"<blob>=") ).head.split( "<blob>=" ).last |