Skip to content

Instantly share code, notes, and snippets.

View oniani's full-sized avatar
:electron:
4845495741

David Oniani oniani

:electron:
4845495741
View GitHub Profile
@oniani
oniani / .bash_profile
Last active October 16, 2018 04:40
Terminal Customization for macOS
# In order to make all the scripts below work, create .colors.csv file with the colors of your choice and drop it in the
# home directory. Since the file starts with . [dot], it won't be visible, yet one can always delete it with rm -r command.
# I think it's better to make it invisible since it's not a file to be used regularly and it might accidentally get deleted.
# Also, you can customize and create as much themes as you wish with combining different font styles/colors and background
# and foreground colors.
# I find these themes extremely handy when it comes to presentations or even switching colors for the daily usage (e.g. when
# it's dark, one might want use colors which are a little bit brighter or maybe even darker according to his/her needs
# and doing it manually is a big pain).
@oniani
oniani / bash_colors.md
Created May 12, 2018 05:25
Terminal Colors

Terminal 8/16 (regular) colors

Value Color Category Value Color Category
\e[0;39m Default color Foreground \e[0;49m Default color Background
\e[0;30m Black Foreground \e[0;40m Black Background
\e[0;31m Red Foreground \e[0;41m Red Background
\e[0;32m Green Foreground \e[0;42m Green Background
\e[0;33m Yellow Foreground \e[0;43m Yellow Background
\e[0;34m Blue Foreground \e[0;44m Blue Background
@oniani
oniani / csv_to_md.py
Last active May 23, 2019 03:54
Generate a markdown table from the list
"""
Author: David Oniani
Created: May 22, 2019
License: GNU General Public Licence v3.0
"""
def longest_in_columns(table) -> int:
"""A simple function to find the longest string sizes for each column."""
# This is a neat way of getting columns
@oniani
oniani / remove_trailing_whitespace.py
Created September 15, 2018 04:26
Remove trailing whitespaces from any program/file
def remove_trailing_whitespace(file):
"""
Function to remove the trailing whitespace
and add a newline in the end.
"""
with open(file, 'r+') as file:
new_file = []
for line in file:
new_file.append(line.rstrip())
file.truncate(0)
@oniani
oniani / .zshrc
Last active March 27, 2019 12:14
Z Shell Configuration
# Customized '.zshrc' file by David Oniani
# Licensed under MIT
# Copyright (c) 2018 David Oniani
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Homebrew settings
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
@oniani
oniani / dijkstra.py
Last active December 3, 2018 16:43
Dijkstra's algorithm
from collections import deque
def generate_graph():
"""
Generate a weighted, directed or undirected graph.
NOTE: A weighted graph is represented as a map of maps.
"""
graph = {}
@oniani
oniani / ghci.conf
Last active November 24, 2018 22:46
My GHCi configuration
-- Change the prompt to lambda
:set prompt "\ESC[34mλ> \ESC[m"
-- Show the types of evaluated expressions
:set +t
-- Show statistics
:set +s
-- Aliases
@oniani
oniani / qlearn.py
Created December 17, 2018 01:58
A generic Q-learning algorithm
"""
A generic Q-learning algorithm
Author: David Oniani
License: MIT
"""
import numpy as np
import random
import gym
@oniani
oniani / dfs_bfs.py
Last active April 2, 2019 03:51
BFS and DFS
from collections import deque
def BFS(graph, start):
visited = set()
new_deque = deque([start])
while new_deque:
node = new_deque.popleft()
if node not in visited:
@oniani
oniani / binary_search.rs
Created August 22, 2019 04:16
A simple recursive binary search in Rust
/// Filename: binary_search.rs
/// Author: David Oniani
/// Date: August 21, 2019
///
/// Slices are powerful!
///
extern crate rand;
use rand::Rng;
/// A simple recursive binary search in Rust