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
""" | |
Search for a text in all repos for an organization. | |
Currently via the web UI you can only search per repo. | |
This will only return number of matches for the text and not | |
the filenames (as of now). | |
You need an OAuth Token for this to work. | |
Run it as: |
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 csv | |
import json | |
input_file = 'PROD_CUSTOMERS_GOOD.csv' | |
output_file = 'wowcher_customer_creation_formatted.json' | |
with open(input_file) as infile: | |
infile.readline() | |
with open(output_file, 'w') as outfile: |
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 QuickSort { | |
def sort(xs: Array[Int]): Array[Int] = { | |
if (xs.length <= 1) xs | |
else { | |
val pivot = xs(xs.length / 2) | |
val lessThanPivot = xs filter (pivot >) | |
val equalToPivot = xs filter (pivot ==) | |
val greaterThanPivot = xs filter (pivot <) | |
println("Pivot for array [%s] is %d".format(xs.deep.mkString(" "), | |
pivot)) |
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 TailRecursiveFactorial { | |
def factorial(n: Int, product: Int): Int = | |
if (n == 1) product else factorial(n - 1, n * product) | |
def main(args: Array[String]) { | |
println("Factorial of 8 is: " + factorial(8,1)) | |
} | |
} |
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 HigherOrderFunctions { | |
def product(f: Int => Int)(a: Int, b:Int): Int = { | |
if (a > b) 1 else f(a) * product(f)(a + 1, b) | |
} | |
def main(args: Array[String]) { | |
println("Product of range of numbers from 3 to 8 is: " + product(x => x)(3,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
object Factorial { | |
def product(f: Int => Int)(a: Int, b:Int): Int = { | |
if (a > b) 1 else f(a) * product(f)(a + 1, b) | |
} | |
def factorial(n: Int): Int = { | |
product(x => x)(1, n) | |
} | |
def main(args: Array[String]) { | |
println("Factorial of 6 is: " + factorial(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
object OperatorOverRange { | |
def operateOverRange(f: Int => Int)(operate: (Int, Int) => Int)(base: Int)(a: Int, b:Int): Int = | |
if (a > b) base else operate(f(a), operateOverRange(f)(operate)(base)(a + 1, b)) | |
def main(args: Array[String]) { | |
println("Sum of range of numbers from 3 to 8 is: " + operateOverRange(x => x)((x,y) => x + y)(0)(3,8)) | |
println("Product of range of numbers from 3 to 8 is: " + operateOverRange(x => x)((x,y) => x * y)(1)(3,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
object FixedPoint { | |
var tolerance = 0.0001 | |
def abs(x: Double) = if (x >= 0) x else -x | |
def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < tolerance | |
def fixedPoint(f: Double => Double)(firstGuess: Double) = { | |
def iterate(guess: Double): Double = { | |
val next = f(guess) | |
println(next) | |
if (isCloseEnough(guess, next)) next | |
else iterate(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
object IntTreeTest { | |
abstract class IntTree | |
case object EmptyTree extends IntTree | |
case class Node(elem: Int, left: IntTree, right: IntTree) extends IntTree | |
def contains(t: IntTree, v: Int): Boolean = t match { | |
case EmptyTree => false | |
case Node(e, l, r) => | |
if (v < e) contains(l, v) | |
else if (v > e) contains(r, v) |
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 ListSort { | |
def isort(xs: List[Int]): List[Int] = | |
if (xs.isEmpty) Nil | |
else insert(xs.head, isort(xs.tail)) | |
def insert(head: Int, xs: List[Int]): List[Int] = | |
if (xs.isEmpty) List(head) | |
else if (head > xs.head) xs.head :: insert(head, xs.tail) | |
else head :: xs | |
def main(args: Array[String]) { |
OlderNewer