Skip to content

Instantly share code, notes, and snippets.

View rbobillot's full-sized avatar

Raphael Bobillot rbobillot

View GitHub Profile
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)
///////////////////
// //
// 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
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
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'
/*
** 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
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{
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 )
}
}
/*
** To bypass SSL, just call
** SSLBypasser.bypassSSL
** in your main
*/
object SSLBypasser
{
import java.security.cert.X509Certificate
import javax.net.ssl._
@rbobillot
rbobillot / parseJson.scala
Last active September 8, 2015 02:14
Little example of powerful JSON parsing in Scala
import scala.io.Source
import scala.util.parsing.json._
object Main
{
/*
** FLICKR SPECIFIC FUNCTIONS
*/
def getFlickrInfosJson( content:String ) = {
val rawJson = content.split("\n")
@rbobillot
rbobillot / dump_mac_keychain_display.scala
Last active January 27, 2016 21:49
Quick Scala program reading a Mac's keychain-dump, and displaying it quite nicely
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