Skip to content

Instantly share code, notes, and snippets.

@adenosinew
adenosinew / getOnlyDirs.py
Last active March 6, 2019 19:47
[Python files] Python libraries related to files and directory #file
from os import listdir
from os.path import join, isdir
onlydirs = [f for f in listdir(os.getcwd()) if isdir(join(os.getcwd(), f))]
print(onlydirs)
@adenosinew
adenosinew / createEngine.py
Last active March 6, 2019 19:49
[Python Database] Work with sqlalchemy, mysqlclient #database
import sqlalchemy as sa
engine = sa.create_engine('dialect+driver://username:password@Host:port/dbname', pool_recycle=3600)
# There was a day where I have too many color schemes in iTerm2 and I want to remove them all.
# iTerm2 doesn't have "bulk remove" and it was literally painful to delete them one-by-one.
# iTerm2 save it's preference in ~/Library/Preferences/com.googlecode.iterm2.plist in a binary format
# What you need to do is basically copy that somewhere, convert to xml and remove color schemes in the xml files.
$ cd /tmp/
$ cp ~/Library/Preferences/com.googlecode.iterm2.plist .
$ plutil -convert xml1 com.googlecode.iterm2.plist
$ vi com.googlecode.iterm2.plist
@adenosinew
adenosinew / listAllSSH.sh
Created April 1, 2019 18:56
[Manage SSH] Manage SSH connections #linux #management
who
who -a
@adenosinew
adenosinew / changeShell.sh
Created April 3, 2019 18:24
[Linux user management] Manage the user profiles in the Linux system #Linux #management
# List All available shells
cat /etc/shells
# Check the detail of user
less /etc/passwd
# e.g. Change the default shell of ubuntu
## 1. usermod
usermod --shell /bin/tcsh ubuntu
@adenosinew
adenosinew / installEFSutils.sh
Last active April 8, 2019 15:26
[Linux mount] Mount volume to instance #aws #Linux
# https://docs.aws.amazon.com/efs/latest/ug/using-amazon-efs-utils.html#installing-other-distro
# Key features of aws efs utils
@adenosinew
adenosinew / CommonDiskOperations.ps1
Last active April 17, 2019 20:45
[Windows management] Useful scripts to manage and tweak Windows system #windows #powershell #cmd
# List Disks
## List all disks
Get-Disk
## List disks that are not system disks
Get-Disk | Where-Object IsSystem -eq $False
## List Disks that are offline
Get-Disk | Where-Object IsOffline -eq $True
@adenosinew
adenosinew / awsDiscovery.sh
Last active April 24, 2019 19:32
[Prometheus Setting] Manage Prometheus server and node exporter #linux #monitoring
# 1. Attach a role that has EC2 read only access to the instance
# 2. Edit the prometheus.yml
# Add the following to the prometheus.yml
- job_name: 'aws'
ec2_sd_configs:
- region: us-east-1
port: 9100
@adenosinew
adenosinew / GetNumericalPermission.sh
Created May 3, 2019 16:23
[Linux Permission] Work with Linux permission #linux #management
# For macOS
stat -f "%OLp" <file>
# For Linux
stat --format '%a' <file>
@adenosinew
adenosinew / CheckNginxSyntax.sh
Created May 3, 2019 18:02
[nginx] Common Nginx settings
nginx -t