This file contains hidden or 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
/** | |
* A question I normally ask in Scala interviews, this is not a tail-recursive implementation | |
*/ | |
object Permutations { | |
def permutations(s: String): List[String] = { | |
def merge(ins: String, c: Char): Seq[String] = | |
for (i <- 0 to ins.length) yield | |
ins.substring(0, i) + c + ins.substring(i, ins.length) |
This file contains hidden or 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
def customToString(x: Int): String = { | |
val digits: Array[Char] = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') | |
def recur(base: Int, digit: Int, accu: List[Char]): List[Char] = { | |
val newAcc = digits(digit) :: accu | |
if (base == 0) newAcc | |
else recur(base / 10, base % 10, newAcc) | |
} | |
val absX = math.abs(x) | |
val toCharList = recur(absX / 10, absX % 10, List.empty) | |
if (x < 0) ('-' :: toCharList).mkString |
This file contains hidden or 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 sys | |
from typing import Dict, List | |
from datetime import datetime | |
import requests | |
from xml.etree import ElementTree | |
BASE_HMRC_URL = 'http://www.hmrc.gov.uk/softwaredevelopers/rates/' #exrates-monthly-0123.XML | |
def main(): |
This file contains hidden or 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 sys | |
from typing import Dict, List | |
ACTION_MAPPING = { | |
"sell": "SELL", | |
"buy": "BUY", | |
"stock plan activity": "BUY", | |
"reinvest shares": "BUY", | |
"stock split": "SPLIT", |
This file contains hidden or 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
-- How does this work? | |
-- -t X -c Y. The number of connections Y is divided evenly on the number of threads. Each thread represents a CPU core that wrk will use. | |
-- wrk sends one request at a time for every connection | |
-- Now, for every thread, we create `num_keys` unique keys, prefixed by a number unique to this particular run of wrk to avoid cache-hit from previous runs. | |
-- The total number of keys that we'll hit is X * num_keys | |
-- Keys are either picked at random or sequential based on the value of `rand_key` | |
local num_keys = 1000000 -- each thread will generate unique keys | |
local counter = 0 | |
local thread_counter = os.time() | |
local threads = {} |