Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Aaroh Mankad aarohmankad

🎯
Focusing
View GitHub Profile
View users.sh
#!/bin/bash
users=($(cat /etc/passwd | awk -F":" '{print $1}'))
uids=($(cat /etc/passwd | awk -F":" '{print $3}'))
for i in "${!users[@]}"; do
groups=($(cat /etc/group | grep "^${users[i]}" | awk -F":" '{print $4}'))
echo ${users[i]} ${uids[i]} $groups
done
View movies.json
{
"payload": [{
"name": "Aquaman",
"stars": 5,
}, {
"name": "Christopher Robin",
"stars": 4.5,
}]
}
View testing_add.cpp
double add(double a, double b) {
return a + b;
}
int main() {
assert(add(3, 4) == 7);
return 0;
}
View testing_add.js
function add(a, b) {
return a + b;
}
let sum = add(3, 4);
if (sum !== 7) {
console.log("add(3, 4) failed. Expected: 7, Actual: " + sum);
}
View import_bash_functions.sh
# 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
View extract_bash_function.sh
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 ;;
@aarohmankad
aarohmankad / handle_errors.cpp
Created Dec 7, 2017
An example of handling some simple edge cases
View handle_errors.cpp
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);
@aarohmankad
aarohmankad / comments.cpp
Last active Dec 7, 2017
A good example showing why to leave comments in your code
View comments.cpp
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 / abstraction.cpp
Last active Dec 28, 2017
An example of code abstraction
View abstraction.cpp
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;