Skip to content

Instantly share code, notes, and snippets.

@deepakduggirala
deepakduggirala / tz.sh
Created February 11, 2021 07:34
Bash TimeZone Converter - MacOS
#!/bin/bash
TZ='CST6CDT' date
TZ='EST' date
TZ='UTC' date
date
while [[ $# -gt 0 ]] && [[ "$1" == "--"* ]] ;
do
opt="$1";
shift; #expose next argument
@deepakduggirala
deepakduggirala / Bash-parameters-default-value.sh
Created November 11, 2019 05:48
Give values to input parameters/arguments when not explicitly provided
#VAR=${1:-DEFAULTVALUE}
#https://coderwall.com/p/s8n9qa/default-parameter-value-in-bash
filename=$1
privatekey="${2:-/Users/user1/.keys/private.pem}"
publickey="${3:-/Users/user1/.keys/public.pem}"
@deepakduggirala
deepakduggirala / ldif-diff.js
Created October 4, 2019 07:01
Shows the difference between two ldif files.
#!/usr/bin/env node
const fs = require('fs')
const decouple = xs => xs.reduce( (acc, curr) => Object.assign(acc, {[curr[0]]: curr[1]}),{});
const intersection = set1 => set2 => new Set([...set1].filter(x => set2.has(x)));
const difference = set1 => set2 => new Set([...set1].filter(x => !set2.has(x)));
function ldif2json(ldif) {
return decouple(
@deepakduggirala
deepakduggirala / Trie.hs
Created November 1, 2018 04:06
Trie Data Structure in Haskell
module Trie where
import qualified Data.Map.Strict as M
import Data.Maybe
import qualified Data.List as L
newtype Trie a = Trie (M.Map a (Trie a)) deriving Show
find :: Ord a => [a] -> Trie a -> Maybe (Trie a)
find [] t = Just t
@deepakduggirala
deepakduggirala / listUtils.hs
Last active November 1, 2018 04:04
Split a List into sublists, List to Tuple, lifting tuples
import qualified Data.List as L
splitEvery :: Int -> [a] -> [[a]]
splitEvery n [] = []
splitEvery n list = first : splitEvery n second
where (first, second) = L.splitAt n list
tuplify2 :: [a] -> (a, a)
tuplify2 [x, y] = (x, y)
tuplify2 _ = error "list does not have 2 elements"
import Control.Monad
import Data.List ( break )
import Data.Function ( (&) )
readList_ :: IO [Int]
readList_ = do
n <- readLn :: IO Int
map read . words <$> getLine
data Tree a = Empty | Node a (Tree a) (Tree a) deriving (Show)
@deepakduggirala
deepakduggirala / readNumbers.hs
Created October 18, 2018 19:33
Haskell IO - Read a number per line
f = id
main = do
inputdata <- getContents
mapM_ (putStrLn. show). f. map read. lines $ inputdata
module Throwaway where
import Control.Monad
import ConvexHull ( grahamScan
, perimeter
)
import Text.Printf
h :: [Int] -> (Int, Int)
h (x : y : []) = (x, y)
module ConvexHull where
import Data.List ( maximumBy
, minimumBy
, sortBy
)
import Data.Ord ( comparing
, Ord
)
@deepakduggirala
deepakduggirala / ghdiff.py
Last active June 8, 2018 12:39
Open git diff in github
import os
import subprocess
import re
import sys
def is_a_git_repo():
return os.path.exists('.git') and os.path.isdir('.git')
def split_SSH_URL(s):
m = re.search('git@(.*?):(.*?)/(.*?).git', s)