Snippets Collections
if [ "$#" -ne 1 ]
then
  echo "Usage: ..."
  exit 1
fi
#!/bin/bash
# Bash Menu Script Example

PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose choice 1"
            ;;
        "Option 2")
            echo "you chose choice 2"
            ;;
        "Option 3")
            echo "you chose choice $REPLY which is $opt"
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done
# List all networks a container belongs to
docker inspect -f '{{range $key, $value := .NetworkSettings.Networks}}{{$key}} {{end}}' [container]
# List all containers belonging to a network by name
docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' [network]
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

if (PHP_SAPI !== 'cli') {
  return;
}

if (version_compare(PHP_VERSION, '5.4.5') < 0) {
  $version = PHP_VERSION;
  echo <<<EOF

ERROR: This script requires at least PHP version 5.4.5. You invoked it with
       PHP version {$version}.
\n
EOF;
  exit;
Esc # exit insert mode
:wq | :x # write and quit
gunzip -c /Users/sethshapiro/Downloads/20210305-KochavaTransactions000000000000.gz | awk 'NR==1 {print; exit}'
#!/bin/bash

if [ ! -f composer.json ]; then
    echo "Please make sure to run this script from the root directory of this repo."
    exit 1
fi

composer install
cp .env.example .env
php artisan key:generate
source "$(dirname "$0")/checkout_latest_docs.sh"
npm install
npm run dev
/home/rezaeir/canu-2.1.1/bin/canu -p lambda -d lambda-assembly genomeSize=50000 -nanopore-raw lambda_subsample.fastq.gz
rasusa --input control_lambda_7_2_2021.fastq.gz --coverage 30 --genomes-size 50000 --output lambda_subsample.fastq.gz
cat *.fastq.gz > control_lambda_7_2_2021.fastq.gz
./guppy_basecaller --compress_fastq -i <input dir> -s <output dir> --flowcell FLO-MIN106 --kit SQK-LSK109 -x "cuda:0" --gpu_runners_per_device 4 --num_callers 4 --chunks_per_runner 2048 --barcode_kits "EXP-NBD104" --trim_barcodes
for file in *
do
file=${file//.bam/}
samtools sort -@ 14 $file.bam > $file.sorted.bam
samtools index -@ 14 -b $file.sorted.bam
samtools idxstats -@ 14 $file.sorted.bam > $file.idxstats.txt
done
#!/usr/bin/env python3
import sys
import subprocess

with open(sys.argv[1]) as f:
        for line in f:
                old_name = line.strip()
                new_name = old_name.replace("jane","jdoe")
                subprocess.run(["mv",old_name,new_name])
        f.close()
#!/bin/bash

>oldFiles.txt
files=$(grep " jane " ../data/list.txt | cut -d ' ' -f 3)
for file in $files; do
        if [ -e $HOME$file ]; then
        echo $HOME$file >> oldFiles.txt;
        fi
done
#!/bin/bash

for logfile in /var/log/*log; do
	echo "Processing: $logfile"
    # the following line splits the logfile entry line with an empty space as delimiter and then keeps only everything from field five onwards
    cut -d" " -f5- $logfile | sort | uniq -c | sort -nr | head -5
done
#!/bin/bash

for file in *.HTM; do
  name=$(basename "$file" .HTM) # surround the filename with double quotes to account for file names with spaces
  echo mv "$file" "$name.html" # put echo in front when testing to see what the program would do without actually changing anything yet
done
#!bin/bash

for fruit in peach orange apple; do # we represent a list in Bash by simply listing valkues/variables with spaces in between
  	echo "I like $fruit!"
done
#!/bin/bash

n=1 # in Bash, there are no spaces allowed when declaring variables
while [ $n -le 5]; do # the "[ condition ]"-syntax is equivalent to the "test" command
  echo "Iteration number $n"
  ((n+=1)) # in Bash, we use double parentheses to perform arithmetic operations on variables
done
#!/bin/bash

echo "Starting at: $(date)" # the dollar sign tells the program to execute this file inside of the string and then convert the output of it into a string
echo # print empty line

# add separating line
line="-----------------------------------"

echo "UPTIME"
uptime
echo $line

echo "FREE"
free
echo $line

echo "WHO"; echo; free # you can write commands on the same line separating them by semicolons

echo "Finishing at: $(date)"
# print message
echo "Test!"

# create new directory
mkdir new_directory

# change directory
cd new_director

# print current working directory
pwd

# copy file
cp ../spider.txt .

# create empty file
touch myfile.txt

# list files and directories in current directory (with additional information using -l, including hidden files -a)
ls
ls -l
ls- la

# combine ls via a pipe to the less command to show only so many entries at a time
ls -l | less # you can quit with "q"

# rename a file
mv my.file.txt emptyfile.txt

# delete a file
rm *
  
# delete an empty directory
rmdir new_directory/
  
# list all running process on the computer
ps-ax
ps-ax | grep ping # filter process names through grep

# kill a process
kill 4619 # where 4619 is the process ID (PID)
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4 
ffmpeg -i input.mkv -codec copy output.mp4
$ find /home/sk/ostechnix/ -type f -printf '%T+ %p\n' | sort | head -n 1
sudo service postgresql status # check db status
sudo service postgresql start # start running db
sudo service postgresql stop # stop running db

sudo /etc/init.d/postgresql restart # restart postgres server

sudo -u postgres createuser --superuser username # create user
sudo -u username createdb dbname # create db

psql -h 127.0.0.1 -U postgres # connect to db
psql -U username -d dbname # open psql command line access db
\d tablename # view table
\dt # show all tables
\q # exit psql console
\du # show all users
\l # show all databases
show hba_file; # get hba_file path
show listen_addresses; # show addresses being listened to

\conninfo # get connection info

python3 manage.py runserver # run server locally
git branch branch-name # create branch
git checkout branch-name # switch to branch
git branch -m branch-name # rename branch
git fetch repo-name # get remote updates
git branch --set-upstream-to=repo-name/remote-branch local-branch # link branches

git branch -d branch-name # delete local branch
git branch -D branch-name # delete unmerged local branch

git log --oneline # view commits
git reset stashhash # view previous commit
git reset --hard # cancel revert commit
git revert HEAD # revert commit remote as well as local

git commit -am "message" # commit
git add . # add another file
git commit --amend --no-edit # add file without changing message

git stash --include-untracked # stashing with untracked files
git stash push -m "stash name" # name stash
git stash list # list stashes
git stash pop stash@{n} # pop stash

# squash branch into one commit
git checkout sprint-branch
git merge --squash task-branch
git commit --amend 'commit message'
git push

# generate ssh key
ssh-keygen
cat ~/.ssh/id_rsa.pub
ffmpeg -ss 6.0 -t 70.0 -i /path/to/file.mp4 -filter_complex "[0:v] fps=12,scale=w=640:h=-1,setpts=0.5*PTS,split [a][b];[a] palettegen [p];[b][p] paletteuse" /path/to/output.gif
#!/bin/bash
#PBS -l nodes=1:ppn=16,walltime=0:00:59
#PBS -l mem=62000mb
#PBS -m abe

bar=${foo}
echo "${bar}"


qsub -v foo='qux' myRunScript.sh

git push heroku master # deploy to heroku

heroku addons:create heroku-postgresql:hobby-dev # create postgres db in heroku app
heroku run python # run python repl with heroku
from app import db
db.create_all()

heroku pg:psql # db shell

heroku run python manage.py db upgrade --app name_of_your_application # upgrade db to heroku
heroku local # run locally on heroku and debug
sudo curl https://raw.githubusercontent.com/TheRemote/PiBenchmarks/master/Storage.sh | sudo bash
#!/usr/bin/env bash

set -e

# Dotfiles' project root directory
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Host file location
HOSTS="$ROOTDIR/hosts"
# Main playbook
PLAYBOOK="$ROOTDIR/dotfiles.yml"

# Installs ansible
apt-get update && apt-get install -y ansible

# Runs Ansible playbook using our user.
ansible-playbook -i "$HOSTS" "$PLAYBOOK" --ask-become-pass

exit 0
# login/ssh to the machine that should host the webserver, then run:
> frecklecute hello-world.frecklet --domain example.com

# or, install the remote target machine from your local session:
> frecklecute --target admin@example.com \
      hello-world.frecklet --domain example.com
# configuration, save as: hello-world.frecklet

- static-website-from-folder:
    hostname: "{{:: domain ::}}"     # vhost config
    path: /var/www/html
    webserver: apache
    use_https: true
    server_admin: hello@example.com  # for let's Encrypt
- file-with-content:
    owner: www-data
    path: /var/www/html/index.html
    content: |
      <h1><i>{{:: domain ::}}</i> says "hello", World!</h1>
pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org flask-wtf
grep -rnwo . -e 'text' # search files for text

sudo mkdir /mnt/z # mount a windows drive in linux
sudo mount -t drvfs Z: /mnt/z
git branch --merged | egrep -v "(^\*|release|dev)" | xargs git branch -d
# Set URL for your scoped packages.
# For example package with name `@foo/bar` will use this URL for download
npm config set @my-org:registry https://private-gitlab.com/api/v4/projects/<your_project_id>/packages/npm/

# Add the token for the scoped packages URL. Replace <your_project_id>
# with the project where your package is located.
npm config set '//private-gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken' "<your_token>"
defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "Router" "Interactor" "Builder" && killall Xcode
defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View" && killall Xcode
defaults write com.apple.screencapture include-date -bool true
wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet
sudo nano /etc/default/grub

# There is a line in that: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" (like this), replace with: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_idle.max_cstate=1"
# Save it (CTRL+O)

sudo update-grub
sudo reboot
firebase functions:config:set stripe.secret="STRIPE_SECRET_KEY_HERE"
// BASH
mkdir src
mkdir build
touch src/index.ts
touch .gitignore
touch README.md
tsc -y
npm init -y
npm install nodemon concurrently @types/express --save-dev

// package.json
...
"scripts": {
  "start:build": "tsc -w",
  "start:run": "nodemon ./build/index.js",
  "start": "concurrently npm:start:*"
},
...

// tsconfig.json
...
"outDir": "./build",
"rootDir": "./src",
...

// .gitignore
node_modules
*.env

// README.md
### Start
```bash
npm run start
```

// src/index.ts
import express from 'express'
const port = 3000
const app = express()

console.log("Hello, World!!!")

logSomething("This is a string that I'm logging")

app.listen(port, () => {
  console.log(`Listening on port ${port}`)
})
touch index.ts
mkdir src
mv index.ts ./src
//Error

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar

//Fix

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/bin/chmod 0600 /var/swap.1
/sbin/swapon /var/swap.1
hello@nobo-prod-server:~$ sudo lsof -i:8082
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node\x20/ 2993 root   20u  IPv6  30271      0t0  TCP *:8082 (LISTEN)
hello@nobo-prod-server:~$ ps 2993
  PID TTY      STAT   TIME COMMAND
 2993 ?        Ssl   28:43 node /home/yasas/nobo-angular/server.js
hello@nobo-prod-server:~$
Restricted : aucun script ne peut être exécuté.

AllSigned : seuls les scripts signés peuvent être exécutés.

RemoteSigned : les scripts téléchargés depuis Internet doivent être signés pour être exécutés. 
	Les scripts présents sur votre poste de travail ne sont pas concernés et peuvent être exécutés.

Unrestricted : pas de restrictions. Les scripts peuvent être exécutés.

connaitre le mode d'execution
	Get-ExecutionPolicy
   
changer le mode d'execution
	Set-ExecutionPolicy <mode>

cree un utilisateur 
	New-ADUser 
		-Name <login> 
		-SamAccountName <login> 
		-UserPrincipaleName <mail> 
		-AccountPassword (ConvertTo-SecureString -AsPlainText <mdp> -Force ) 
		-PasswordNeverExpires $true
		-CannotChangePassword $true

activer Utilisateur
	Enable-ADAccount <samaccountname>
	Desable-ADAccount <samaccountname>

lancer script 
	powershell .\PATH

rechercher des utilisateur
	Get-ADUser -Filter *
	Get-ADUser -Filter * | select samAccountName, Name, UserPrincipalName | Export-Csv UserAdUTF8.csv -Encoding UTF8


cree un groupe 
	New-ADGroup $groupe -GroupScope Global

inserer des utilisateur dans un groupe
	Add-ADGroupMember -identity $groupe -Members <samAccountName>

recherche groupe
	Get-ADGroup -Filter *

afficher les utilisateur dans un groupe
	 Get-ADGroupMember $group | Select-Object name  | Export-Csv SEC.csv -Encoding UTF8

ide for powershell
	Notepad.exe	
git rev-parse --show-toplevel

could be enough if executed within a git repo.
From git rev-parse man page:

--show-toplevel
# WARNING: This will LOCK ALL PUBLIC REPOSITORIES ON YOUR GITHUB ACCOUNT
#
# dependencies hub and jq
# - hub: hub.github.com
# - jq: https://stedolan.github.io/jq/
#
# A better alternative would be to pipe the repos into a temporary file:
# $ hub api --paginate users/amingilani/repos | jq -r '.[]."full_name"' > repos.txt
# Then manually remove your active repositories
# And archive the remaining:
# $ cat repos.txt | xargs -I {} -n 1 hub api -X PATCH -F archived=true /repos/{}
#
# Anyways, to archive all public repositories in your GitHub account:
#
hub api --paginate users/amingilani/repos | jq -r '.[]."full_name"' | xargs -I {} -n 1 hub api -X PATCH -F archived=true /repos/{}
 https://cronhub.io/ping/1f5e3410-254c-11e8-b61d-55875966d031
star

Sat Apr 24 2021 21:04:50 GMT+0000 (UTC)

#bash
star

Sat Apr 24 2021 21:00:41 GMT+0000 (UTC) https://askubuntu.com/questions/1705/how-can-i-create-a-select-menu-in-a-shell-script

#bash
star

Tue Apr 20 2021 17:12:01 GMT+0000 (UTC) https://maximorlov.com/4-reasons-why-your-docker-containers-cant-talk-to-each-other/

#bash
star

Tue Apr 20 2021 17:11:50 GMT+0000 (UTC) https://maximorlov.com/4-reasons-why-your-docker-containers-cant-talk-to-each-other/

#bash
star

Sun Apr 18 2021 16:35:19 GMT+0000 (UTC)

#ubuntu #bash #linux
star

Tue Apr 06 2021 15:27:19 GMT+0000 (UTC)

#bash
star

Tue Apr 06 2021 08:53:58 GMT+0000 (UTC)

#bash
star

Wed Mar 31 2021 14:58:05 GMT+0000 (UTC)

#bash
star

Wed Mar 31 2021 06:35:25 GMT+0000 (UTC) https://github.com/laravel/laravel.com-next/blob/master/bin/setup.sh

#bash
star

Sun Mar 28 2021 12:54:21 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #gzip
star

Sun Mar 28 2021 12:53:33 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #assembly #canu
star

Sun Mar 28 2021 12:52:57 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #wgs #subsample #rasusa
star

Sun Mar 28 2021 12:51:52 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #fastq #join
star

Sun Mar 28 2021 12:51:14 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #guppy #nanopore #basecall
star

Sun Mar 28 2021 12:49:54 GMT+0000 (UTC) https://www.notion.so/rezaeir/Code-Snippets-f347e2e7bc2d4217854f17cb0a5e0746

#bash #samtools #bam #count
star

Sun Mar 28 2021 11:12:42 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 11:12:11 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 09:50:19 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 09:48:07 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 09:42:01 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 09:19:34 GMT+0000 (UTC)

#bash
star

Sun Mar 28 2021 09:18:21 GMT+0000 (UTC)

#bash
star

Sun Mar 21 2021 04:37:24 GMT+0000 (UTC)

#bash
star

Sun Mar 21 2021 04:34:01 GMT+0000 (UTC)

#bash
star

Sat Mar 20 2021 07:37:59 GMT+0000 (UTC) https://ostechnix.com/find-oldest-file-directory-tree-linux/

#bash
star

Thu Mar 18 2021 08:35:27 GMT+0000 (UTC)

#bash
star

Wed Mar 17 2021 09:27:36 GMT+0000 (UTC)

#bash
star

Mon Mar 15 2021 13:38:05 GMT+0000 (UTC) https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/

#bash
star

Fri Mar 12 2021 21:07:11 GMT+0000 (UTC) https://stackoverflow.com/a/17068891

#bash
star

Fri Mar 12 2021 11:02:42 GMT+0000 (UTC)

#python #bash
star

Thu Mar 11 2021 12:17:01 GMT+0000 (UTC) https://stackoverflow.com/questions/54066437/date-month-in-bash-without-leading-0-or-space

#bash
star

Sat Mar 06 2021 23:08:44 GMT+0000 (UTC) https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/

#bash
star

Wed Mar 03 2021 04:09:21 GMT+0000 (UTC) https://thebroken.link/managing-dotfiles-with-ansible/

#bash #ansible
star

Wed Mar 03 2021 03:43:25 GMT+0000 (UTC) https://freckles.io/

#bash #freckles
star

Wed Mar 03 2021 03:43:09 GMT+0000 (UTC) https://freckles.io/

#bash #freckles
star

Mon Feb 15 2021 16:00:50 GMT+0000 (UTC)

#bash #python
star

Mon Feb 15 2021 09:17:53 GMT+0000 (UTC)

#bash
star

Mon Feb 08 2021 16:11:59 GMT+0000 (UTC)

#bash
star

Tue Dec 29 2020 20:45:20 GMT+0000 (UTC)

#bash
star

Sat Dec 12 2020 01:14:26 GMT+0000 (UTC) https://macos-defaults.com/xcode/ideadditionalcounterpartsuffixes.html

#bash
star

Sat Dec 12 2020 01:14:26 GMT+0000 (UTC) https://macos-defaults.com/xcode/ideadditionalcounterpartsuffixes.html

#bash
star

Sat Dec 12 2020 01:13:52 GMT+0000 (UTC) https://macos-defaults.com/screenshots/include-date.html

#bash
star

Wed Dec 09 2020 00:38:46 GMT+0000 (UTC) https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md

#bash
star

Sun Dec 06 2020 21:15:55 GMT+0000 (UTC) https://askubuntu.com/questions/761706/ubuntu-15-10-and-16-04-keep-freezing-randomly

#bash #ubuntu
star

Wed Dec 02 2020 19:20:04 GMT+0000 (UTC)

#bash
star

Sun Nov 29 2020 16:44:07 GMT+0000 (UTC) https://forums.docker.com/t/start-a-gui-application-as-root-in-a-ubuntu-container/17069

#bash #docker #ubuntu
star

Wed Nov 18 2020 12:29:43 GMT+0000 (UTC) https://blog.sodifrance.fr/nmap-commandes-utiles/

#bash
star

Wed Nov 18 2020 00:08:27 GMT+0000 (UTC) https://youtu.be/1__Leh5MBEM

#bash
star

Sun Nov 08 2020 17:58:52 GMT+0000 (UTC)

#bash
star

Tue Oct 27 2020 05:59:09 GMT+0000 (UTC) https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors

#bash
star

Thu Oct 08 2020 05:35:47 GMT+0000 (UTC)

#bash
star

Tue Oct 06 2020 09:30:19 GMT+0000 (UTC)

#bash
star

Sun Oct 04 2020 00:52:52 GMT+0000 (UTC)

#shell #bash
star

Sat Jun 13 2020 08:20:55 GMT+0000 (UTC) https://www.computerhope.com/unix/signals.htm

#bash #linux
star

Sat Jun 06 2020 16:35:29 GMT+0000 (UTC) chrome-extension://annlhfjgbkfmbbejkbdpgbmpbcjnehbb/images/saveicon.png

#bash
star

Thu Jun 04 2020 19:50:21 GMT+0000 (UTC) https://stackoverflow.com/questions/12293944/how-to-find-the-path-of-the-local-git-repository-when-i-am-possibly-in-a-subdire

#bash
star

Wed Jun 03 2020 13:35:00 GMT+0000 (UTC)

#bash
star

Fri May 22 2020 13:55:18 GMT+0000 (UTC) https://docs.cronhub.io/

#bash

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension