Skip to content

Instantly share code, notes, and snippets.

View samidarko's full-sized avatar

Sami Darko samidarko

View GitHub Profile
@samidarko
samidarko / parentheseBalance.hs
Created September 9, 2016 14:22
Returns True if the parentheses in the input string is balanced
parentheseBalance :: String -> Bool
parentheseBalance s = f s 0
where
f s c
| s == [] = c == 0 -- if string is empty, return true if count == 0
| c < 0 = False
| head s == '(' = f (tail s) (c+1)
| head s == ')' = f (tail s) (c-1)
| otherwise = f (tail s) c
@samidarko
samidarko / MergeSort.scala
Created September 20, 2016 10:10
Merge Sort in Scala
/**
* Created by samidarko on 9/20/16.
*/
import util.Random
object MergeSort extends App {
def merge(left: List[Int], right: List[Int]) : List[Int] = {
if (left.isEmpty) right
else if (right.isEmpty) left
@samidarko
samidarko / init.vim
Created September 20, 2016 14:23
my nvimrc file
" plugins config
set runtimepath+=~/.config/nvim/repos/github.com/Shougo/dein.vim/
call dein#begin(expand('~/.config/nvim'))
call dein#add('Shougo/dein.vim')
call dein#add('othree/yajs.vim', {'on_ft': 'javascript'})
call dein#add('othree/jsdoc-syntax.vim', {'on_ft':['javascript']})
call dein#add('othree/es.next.syntax.vim', {'on_ft': 'javascript'})
@samidarko
samidarko / functional.js
Last active May 2, 2017 22:38
functional programming: head, last, init, tail, reduce, map, filter, reduceRight, mapWithReduceRight, filterWithReduceRight, reduceLeftWithReduceRight
// import R from 'ramda';
// TODO improve signature like add index and array
const arr = [1, 2, 3, 4, 5];
function assertNotEmpytList(fnName, list) {
if (list.length === undefined || list.length <= 0) throw new Error(`${fnName}: empty list`);
}
function id(x) {
import Data.List (genericLength)
mean xs = sum xs / genericLength xs
variance xs = (sum [ (x - m)^2 | x <- xs ]) / genericLength xs
where m = mean xs
standardDeviation xs = sqrt $ variance xs
#!/usr/bin/env bash
cd ${HOME}/mining/monitoring
module="eth"
set -e
GPU_LIST_USAGE=( `/opt/bin/nvidia-smi --query-gpu="utilization.gpu" --format=csv,noheader,nounits` )
total=0
for GPU in "${GPU_LIST_USAGE[@]}"
@samidarko
samidarko / start.sh
Created October 1, 2017 03:52
zec/start.sh
#!/usr/bin/env bash
cd ${HOME}/zec
SRV="eu1-zcash.flypool.org:3333"
ADDRESS=""
RIG=`hostname`
data Expr = Val Int | Div Expr Expr deriving Show
eval :: Expr -> Int
eval (Val x) = x
eval (Div x y) = eval x `div` eval y
safeDiv :: Int -> Int -> Maybe Int
safeDiv n m = if m == 0 then Nothing else Just (n `div` m)
safeEval :: Expr -> Maybe Int
@samidarko
samidarko / search_sum_of_pair_in_array.py
Last active March 8, 2018 06:37
Find if sum a of pair of integer exists in an array
def brute_force(arr, s):
for i in arr:
for j in arr:
if i + j == s:
print("{} + {} = {}".format(i, j, s))
# brute_force([5, 3, 7, 0, 1, 4, 2], 5)
@samidarko
samidarko / polygon.hs
Last active March 8, 2018 09:53
dentify whether four sides (given by four integers) can form a square, a rectangle, or neither.
import Data.List.Split (splitOn)
-- polygons.txt
-- 36 30 36 30
-- 15 15 15 15
-- 46 96 90 100
-- 86 86 86 86
-- 100 200 100 200
-- -100 200 -100 200