Skip to content

Instantly share code, notes, and snippets.

View Haaroon's full-sized avatar

Haaroon Y Haaroon

View GitHub Profile
@Haaroon
Haaroon / Dockerfile
Created June 24, 2018 16:00
Parity Ethereum Client Docker file
FROM ubuntu:14.04
WORKDIR /build
# install tools and dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
build-essential \
curl \
git \
@Haaroon
Haaroon / tally.py
Created November 7, 2018 12:51
Tally matches from a cricket calendar
from icalendar import Calendar
g = open('calendar_name.ics','rb')
gcal = Calendar.from_ical(g.read())
tally = {
'U8':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0},
'U9':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0},
'U10':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0},
'U11':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0},
'U12':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0},
@Haaroon
Haaroon / docker download link
Created September 23, 2019 13:14
Download docker without logging into the website. Docker link
@Haaroon
Haaroon / readme.txt
Created July 6, 2020 15:18
Extract from gzip , remove duplicates from csv but keep header, then gzip result
# Extract a csv file from a gzip but keep the original gzip zcat file_compressed.csv.gz
# cut the two columns of the file and save it cut -d',' -f1,2 > file_uncompressed.csv
zcat file_compressed.csv.gz | cut -d',' -f1,2 > file_uncompressed.csv
# Since its a csv with a header keep this header head -n1 file_uncompressed.csv
# but get the result of the file, sort it, uniq to
# remove duplicates, +2 so we start at line 2 tail -n +2 file_uncompressed.csv | sort | uniq
# gzip the result and save into new file gzip > file_compressed_no_dups.csv.gz
(head -n1 file_uncompressed.csv && tail -n +2 file_uncompressed.csv | sort | uniq) | gzip > file_compressed_no_dups.csv.gz
@Haaroon
Haaroon / Rename branch from main to master
Last active August 2, 2023 21:32
Rename branch from main to master
git branch -m main master
git push -u origin master
git remote set-head origin master
# Now go to github in a browser,
# open the repo, click settings, branch and change the default branch to master
git push origin --delete main
implicit class DateInterpolator(val sc: StringContext) extends AnyVal {
def date(args: Any*): LocalDate = {
if (args.length != 3) throw new IllegalArgumentException("Need 3 inputs")
else {
try {
var year = args(0).toString.toInt
var month = args(1).toString.toInt
var day = args(2).toString.toInt
LocalDate.of(year, month, day)
} catch {
def randomArr(n: Int)={
val rnd = new scala.util.Random
val rands = new Array[Int](n)
for (i <- 0 until rands.length)
rands(i) = rnd.nextInt(n)
rands
}
def swapElements(ogArray: Array[Int]) = {
var adjacent_pos = 0
// ex 2
val in = new java.util.Scanner(new java.io.File("example.txt"))
val words = scala.collection.mutable.Map[String, Int]()
while (in.hasNext()) {
val word = in.next().replaceAll("\\W", "")
val c = words.getOrElse(word, 0) + 1
words(word) = c
}
for((k,v) <- words) println(k +" : "+ v)
// ex1
class Counter {
private var value = 0
def increment() {
if (value != Int.MaxValue)
value += 1
}
}
// ex2
// 1. Write an object Conversions with methods inchesToCentimeters, gallonsToLiters, and milesToKilometers.
object Conversions {
def inchesToCentimeters(value: Double)={
// 1 inch = 2.54
value * 2.54
}
def gallonsToLiters(value: Double)={
// 1 gallon = 3.78541 liters
value * 3.78541