Skip to content

Instantly share code, notes, and snippets.

View aarohmankad's full-sized avatar
🎯
Focusing

Aaroh Mankad aarohmankad

🎯
Focusing
View GitHub Profile
# make directory and change working directory to it
function mcd {
if [ $# -ne 1 ]; then
echo "Usage: mcd <directory-name>"
return
fi
mkdir $1
cd $1
}
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'pangloss/vim-javascript'
Plugin 'mattn/emmet-vim'
@aarohmankad
aarohmankad / bad_names.cpp
Created December 6, 2017 01:42
An example of bad naming conventions
vector<pair<int, int>> getThem() {
vector<pair<int, int>> v;
for (pair<int, int> x : theList) {
if (x.second == 4) {
v.push(x);
}
}
return v;
vector<pair<int, int>> getThem() {
vector<pair<int, int>> v;
for (pair<int, int> x : theList) {
if (x.second == 4) {
v.push(x);
}
}
return v;
@aarohmankad
aarohmankad / abstraction.cpp
Last active December 28, 2017 19:34
An example of code abstraction
vector<Cell> findCells(const vector<Cell>& gameBoard, const int FLAG_CODE) {
vector<Cell> cells;
for (Cell cell : gameBoard) {
if (cell.status == FLAG_CODE) {
cells.push_back(cell);
}
}
return cells;
@aarohmankad
aarohmankad / comments.cpp
Last active December 7, 2017 00:52
A good example showing why to leave comments in your code
int hash(string input) {
int output = 5381;
// Less collisions than simply adding ASCII characters of value
// simple method: hash("tab") = hash("bat")
// this method: hash("tab") != hash("bat")
for (char c : input) {
output += (output << 5) + c;
}
@aarohmankad
aarohmankad / handle_errors.cpp
Created December 7, 2017 19:09
An example of handling some simple edge cases
vector<pair<int, int>> findCells(const vector<pair<int, int>>& gameBoard, const int FLAG_CODE) {
if (gameBoard.empty()) {
return vector<pair<int, int>> {};
}
vector<pair<int, int>> cells;
for (pair<int, int> cell : gameBoard) {
if (cell.second == FLAG_CODE) {
cells.push_back(cell);
alias extract='tar xvzf'
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ./$1 ;;
# Functions.
# These are like aliases, but can take arguments
# All functions are in ~/.bash_functions for modularity
if [ -f ~/.bash_functions ]; then
. ~/.bash_functions
fi