Skip to content

Instantly share code, notes, and snippets.

View sherifkandeel's full-sized avatar

Sherif Mohamed sherifkandeel

View GitHub Profile
@sherifkandeel
sherifkandeel / colortrans.py
Created September 9, 2016 00:20 — forked from MicahElliott/colortrans.py
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code
@sherifkandeel
sherifkandeel / Scala-std
Created October 13, 2018 14:44
Scala concepts
- Abstract class vs trait
- how does traits prevent the diamond problem
- Algebraic data types over options
- Cake pattern, why you shouldn't use it
- extends product with serializable
- case object, case class vs object, class
- value classes
- type classes
- Monads of the standard library
- Option
@sherifkandeel
sherifkandeel / MapCompare.scala
Created May 10, 2019 14:26
Comparing different Scala Map performance
import scala.collection.concurrent
import scala.collection.immutable._
val concurrentTrieMap: concurrent.Map[String, String] = concurrent.TrieMap.empty
var immutableMap: Map[String, String] = Map.empty
var hashMap: HashMap[String, String] = HashMap.empty
def time[R](block: => R): String = {
val t0 = System.nanoTime()
@sherifkandeel
sherifkandeel / reductionCompare.scala
Created October 28, 2019 13:01
Comparing different ways to get minimum of a collection
case class TestCaseClass(cost: Float, other1: Int, other2: String, other3: String)
val r = new scala.util.Random(31)
val tenkList = 1 to 10000 map (_ => TestCaseClass(r.nextFloat(), r.nextInt, r.alphanumeric.take(3).mkString, ""))
val millionList = 1 to 1000000 map (_ => TestCaseClass(r.nextFloat(), r.nextInt, r.alphanumeric.take(3).mkString, ""))
val tenMillionList = 1 to 10000000 map (_ => TestCaseClass(r.nextFloat(), r.nextInt, r.alphanumeric.take(3).mkString, ""))
def time[R](block: => R): Long = {
val t0 = System.currentTimeMillis()
block
val t1 = System.currentTimeMillis()