Skip to content

Instantly share code, notes, and snippets.

@nestoru
nestoru / tree-gitignore.sh
Created February 20, 2024 12:09
cd git-project && /opt/scripts/tree-gitignore.sh
#!/bin/bash
# /opt/scripts/tree-gitignore.sh
# Author: Nestor Urquiza
# Date: 20240220
# Description: A tree wrapper to show contents of a git project respecting .gitignore
# Usage: cd git-project && /opt/scripts/tree-gitignore.sh
cmd="tree -a -I '.git'"
@nestoru
nestoru / clichatgpt.py
Created May 12, 2023 08:06
A CLI script to interact with ChatGPT via API
#!/usr/bin/env python3
#
# clichatgpt.py
#
# A CLI script to interact with ChatGPT via API
#
# Nestor Urquiza 20230512
#
import sys
import openai
@nestoru
nestoru / Solution for mysql Warning: Using a password on the command line interface can be insecure
Last active October 23, 2021 21:20
Solution for mysql Warning: Using a password on the command line interface can be insecure
# Let us consider the following typical mysql backup script:
mysqldump --routines --no-data -h $mysqlHost -P $mysqlPort -u $mysqlUser -p$mysqlPassword $database
# It succeeds but stderr will get:
# Warning: Using a password on the command line interface can be insecure.
# You can fix this with the below hack:
credentialsFile=/mysql-credentials.cnf
echo "[client]" > $credentialsFile
echo "user=$mysqlUser" >> $credentialsFile
echo "password=$mysqlPassword" >> $credentialsFile
@nestoru
nestoru / ubuntu-install-xrdp.sh
Last active August 30, 2021 12:58
Install XRDP in Ubuntu
#!/bin/bash -e
#
# ubuntu-install-xrdp.sh
# Tested in Ubuntu 20.04: Bidirectional clipboard does work.
#
# One line installer (change ubuntu by the username that you want to remotely login):
# curl -L https://gist.github.com/nestoru/fee24a59804d60ccba1a/raw | sudo bash -s ubuntu
#
START=$(date +%s)
@nestoru
nestoru / mongo-collection-to-csv.sh
Last active February 18, 2021 00:06
mongo-collection-to-csv.sh
#!/bin/bash -e
# mongo-collection-to-csv.sh
#
# description: Exports all field from any mongodb collection to CSV
# author: Nestor Urquiza
# date: 20210218
# env vars
password=$MONGODB_PWD
@nestoru
nestoru / Devops need no words but code: How to forward all Solaris user emails to an external email account
Last active October 23, 2020 00:18
How to forward all Solaris user emails to an external email account
smarthost=mail.sample.com
user=me
alertlist=alert@mail.sample.com
/opt/csw/bin/gsed -i "s/^DS[\s]*.*/DS $smarthost/g" /etc/mail/submit.cf
/opt/csw/bin/gsed -i "s/^DS[\s]*.*/DS $smarthost/g" /etc/mail/sendmail.cf
/opt/csw/bin/gsed -i "/$user:/d" /etc/mail/aliases
echo "$user:$alertlist" >> /etc/mail/aliases
/opt/csw/bin/gsed -i "/root:/d" /etc/mail/aliases
echo "root:$alertlist" >> /etc/mail/aliases
newaliases
@nestoru
nestoru / keep-printing-not-empty-directory-listing.sh
Last active October 10, 2020 11:22
keep printing not empty directory listing - bash one liner
dir=$1
while true; do sleep 5; [ ! -z "$(ls $dir)" ] && date && ls -alrt $dir; done
@nestoru
nestoru / Ubuntu MongoDB install
Last active September 3, 2020 08:42
Ubuntu MongoDB install
# Mongo 3
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv BC711F9BA15703C6
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3-4.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.0.16 mongodb-org-server=3.0.16 mongodb-org-shell=3.0.16 mongodb-org-mongos=3.0.16 mongodb-org-tools=3.0.16
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
@nestoru
nestoru / ubuntu-flush-dns
Created July 14, 2020 18:17
Flush DNS in Ubuntu
sudo systemd-resolve --flush-caches
@nestoru
nestoru / print-older-than-seconds.sh
Created June 12, 2020 10:19
One liner to find processes that have been running for over any amount of seconds
# One liner to find processes that have been running for over any amount of seconds
SECONDS=$1
ps -e -o "pid,etimes,command" | awk '{if($2>$SECONDS) print $0}'
: '
Explanation:
===========
ps: process snapshot command
-e: list all processes
-o: include only specified columns