Skip to content

Instantly share code, notes, and snippets.

View aakbar5's full-sized avatar

asad akbar aakbar5

View GitHub Profile
# Script is interested to take
# - a flag
# - an option which takes a parameter
arg_list=$(getopt -o bp: --long boolean,param: -- "$@")
eval set -- "$arg_list"
while [ $# -gt 0 ] ; do
case "$1" in
-b | --boolean)
echo "Parameter @ flag"
shift
@aakbar5
aakbar5 / cppcheck - installation
Last active September 10, 2020 21:09
cppcheck
# Pre-built package (# Ubuntu 18.04.3 LTS)
sudo apt update
sudo apt install cppcheck
# Build from code
wget https://github.com/danmar/cppcheck/archive/2.1.tar.gz
tar zxvf 2.1.tar.gz
cd cppcheck-2.1
mkdir build
@aakbar5
aakbar5 / .desktop
Last active May 2, 2023 18:48
Ubuntu .desktop file
[Desktop Entry]
Type=Application
Name=EclipseC++
GenericName=Eclipse
Comment=Eclipse for development
Exec=/path/to/eclipse
Icon=/path/to/icon.xpm
Terminal=false
MimeType=text/plain;
Categories=Development;IDE
@aakbar5
aakbar5 / function.sh
Created December 31, 2019 12:09
Bash function
# A simple function which takes
# no parameters and returns nothing
function fun1() {
echo "A simple function"
}
# A function which takes parameters
# and return nothing
function fun2() {
echo "Fun:: Number of parameters: ${#@}"
@aakbar5
aakbar5 / dup2_usage.c
Last active December 27, 2019 11:37
dup2 usage
// A simple example of how dup2 can be used
const char* msg = "Text written by standard file descriptor\n";
int fd = open("dup2_test.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
write(fd, msg, strlen(msg));
/* Map stdout to our file */
dup2(fd, STDOUT_FILENO);
printf("Text written by dup @ stdout file descriptor\n");
close(fd);
@aakbar5
aakbar5 / include-what-you-need - installation
Last active September 10, 2020 21:08
include-what-you-need
# Ubuntu 18.04.3 LTS
# Installation
sudo apt-get update
sudo apt-get install -y build-essential cmake git zlib1g-dev libncurses5-dev llvm-6.0-dev libclang-6.0-dev libclang-6.0-dev clang-6.0
git clone https://github.com/include-what-you-use/include-what-you-use.git iwyu.git
cd iwyu.git
git checkout clang_6.0
mkdir -p build
cd build
cmake -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-6.0 ..
@aakbar5
aakbar5 / Ubuntu: Bash history management
Created October 31, 2019 12:24
Ubuntu: Bash history management
# To see top commands
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
# To remove a commands from history
# Replace YOUR_COMMAND with the initials of the command you want to remove from bash history
sed -i '/^YOUR_COMMAND/d' ~/.bash_history
@aakbar5
aakbar5 / Ubuntu: Setup FTP server
Created October 24, 2019 11:19
Ubuntu: Setup FTP server
# Setup FTP server
# Instructions are tested on: Ubuntu 18.04.3 LTS
apt install -y atftpd
sudo gedit /etc/default/atftpd
# - set USE_INETD=FALSE
# - Optional: To change directory to host FTP contents, change /srv/tftp in OPTIONS line
# - Optional: To have maximum log: change --verbose=7 and append --logfile /var/log/atftpd.log
@aakbar5
aakbar5 / Tensorflow: configure grappler
Created August 17, 2019 20:20
Tensorflow: configure grappler
// Tensorflow session
tensorflow::SessionOptions session_opts;
tensorflow::OptimizerOptions* options = session_opts.config.mutable_graph_options()->mutable_optimizer_options();
// Disable optimizations
options->set_opt_level(tensorflow::OptimizerOptions::L0);
// Grappler related optimizations
auto config = session_opts.config.mutable_graph_options()->mutable_rewrite_options();
config->set_layout_optimizer(tensorflow::RewriterConfig::OFF);
@aakbar5
aakbar5 / Merge pdf files
Created July 16, 2019 10:52
Merge pdf files
#!/bin/bash
# This script merge all pds found in a folder
# Where $1 is folder name
FOLDER="$1"
FILE_COUNT="$(ls $FOLDER/*.pdf | wc -l)"
NEW_NAME="merged-pdfs-$FILE_COUNT-$(cat /dev/urandom | tr -dc '0-9a-zA-Z' | fold -w 16 | head -n 1).pdf"
CMD="gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$NEW_NAME"