Skip to content

Instantly share code, notes, and snippets.

View taintech's full-sized avatar

Rinat Tainov taintech

  • 06:42 (UTC +02:00)
View GitHub Profile
@taintech
taintech / bubbleSort.scala
Created March 10, 2018 14:10
Scala bubble sort implementation
object sortings {
def swap(ar: Array[Int], i: Int, j: Int): Array[Int] = {
val temp = ar(i)
ar(i) = ar(j)
ar(j) = temp
ar
}
def bubbleSort(ar: Array[Int]): Array[Int] = {
@taintech
taintech / mergeSort.scala
Created March 10, 2018 13:25
Scala merge sort implementation
import scala.annotation.tailrec
object sortings {
//p <= q < r
def merge(ar: Array[Int], p: Int, q: Int, r: Int): Array[Int] = {
val x = q - p + 1
val left = new Array[Int](x + 1)
Array.copy(ar, p, left, 0, x)
left(left.length - 1) = Int.MaxValue
@taintech
taintech / InsertionSort.scala
Last active March 5, 2018 20:56
Scala insertion sort implementation
import scala.annotation.tailrec
object sortings {
def insertionSort(ar: Array[Int]): Array[Int] = {
@tailrec
def loop(i: Int, key: Int): Int =
if (i < 0 || ar(i) < key) i + 1
else {
ar(i + 1) = ar(i)
loop(i - 1, key)
@taintech
taintech / LoggingUtility.scala
Created February 4, 2018 06:53
Scala Utility methods for logging
trait Utility extends LazyLogging {
def log(future: Future[_])(
implicit executionContext: ExecutionContextExecutor): Unit = {
val start = System.currentTimeMillis()
future.onComplete {
case Success(res) =>
logger.info(
s"Result in ${System.currentTimeMillis() - start} ms is $res")
case Failure(e) =>
@taintech
taintech / print_case_class.scala
Last active February 3, 2018 20:27
Scala print case class members name and values
object helper {
def printCaseClass(caseClass: AnyRef): Unit = {
def caseClassToMap(caseClass: AnyRef): Map[String, Any] = {
(Map.empty[String, Any] /: caseClass.getClass.getDeclaredFields) {
(a, f) =>
f.setAccessible(true)
a + (f.getName -> f.get(caseClass))
}
@taintech
taintech / get_barcode_from_image.js
Last active February 3, 2018 20:26 — forked from tobitailor/get_barcode_from_image.js
Code to get identify barcode
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',