Skip to content

Instantly share code, notes, and snippets.

View AhmedSoliman's full-sized avatar

Ahmed Farghal AhmedSoliman

View GitHub Profile
@AhmedSoliman
AhmedSoliman / schwab_transpose_csv.py
Last active January 8, 2023 22:35
A script to transpose Schwab's transaction CSV to a slightly more friendly format for galloway's https://github.com/mattjgalloway/cgtcalc
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",
@AhmedSoliman
AhmedSoliman / hmrc_tax_usd.py
Created January 8, 2023 22:30
A tiny little script to get USD to GBP conversion rate for a given date from HMRC
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():
@AhmedSoliman
AhmedSoliman / toString.scala
Created April 26, 2015 15:33
A sample quiz answer on how to create toString without relying on primitive toString method for integers
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
@AhmedSoliman
AhmedSoliman / permutations.scala
Created October 8, 2014 09:24
Generate Permutations of String in Scala
/**
* 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)