Skip to content

Instantly share code, notes, and snippets.

View gargolito's full-sized avatar

Anthony Camilo gargolito

View GitHub Profile
@gargolito
gargolito / tuned_override_python3.txt
Last active May 25, 2020 23:03
override python2 for tuned on ubuntu with python3
Cause
tuned expects python2 as its intepreter. the script does not specify the python version and it installs all of the modules are installed in /usr/lib/python2.7/. If you have python3 installed, the service will fail to start because python3 does not have the *tuned* module dependencies. The sanest solution that should survive upgrades and changes to tuned python, is to give the systemd service the correct python environment in which to execute via override. Until, of course, tuned gets ported to python3.
tested with tuned 2.9.0-1 in ubuntu 18.04
1. sudo apt-get install tuned
2. sudo systemctl edit tuned
[Service]
Environment=PYTHONHOME=/usr/lib/python2
Environment=PYTHONEXECUTABLE=/usr/bin/python2
@gargolito
gargolito / progress_copy.py
Created February 20, 2020 03:51
python copy file with progress bar in terminal
import os
from io import BytesIO
from tqdm import tqdm
file = 'FILENAME'
fsize = int(os.path.getsize(file))
new = 'NEWFILENAME'
with open(file, 'rb') as f:
with open(new, 'ab') as n:
with tqdm(ncols=60, total=fsize, bar_format='{l_bar}{bar} | Remaining: {remaining}') as pbar:
buffer = bytearray()
@gargolito
gargolito / vid2gif
Created January 13, 2020 15:24
ffmpeg for video to gif
function vid2gif () {
vid="$1"
#start_time=00:00:01
#duration=5
height=-1 # input height halved , can replace with pixils .
width=480 # keeps aspect ratio . can replace with pixils .
fps=25 # frames per a second .
filters="fps=$fps,scale=$width:$height:flags=lanczos"
@gargolito
gargolito / systemd snippets.txt
Created September 26, 2019 14:55
#linux #systemd
# lint a service unit file.
sudo systemd-analyze verify foobar.service
@gargolito
gargolito / vim_shortcuts.md
Created September 25, 2019 21:43
#linux #vim

Code formatting

  • :set list, \l - show invisibles
  • :retab! - auto converting between tabs and spaces
    • :set expandtab, retab! - to spaces
    • :set noexpandtab, retab! - to tabs
  • . - repeat
Command Editing Shortcuts
ctrl+a, ctrl+e Go to the start/end of the command line
ctrl+u, ctrl+k Delete from cursor to the start/end of the command line
ctrl+w, alt+d Delete from cursor to start/end of word (whole word if at the boundary)
ctrl+y Paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
ctrl+xx Move between start of command line and current cursor position (and back again)
alt+b, alt+f Move backward/forward one word (or go to start of word the cursor is currently on)
alt+C Capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
alt+u Make uppercase from cursor to end of word
watch -n1 -d "iptables -vnxL | grep -v -e pkts -e Chain | sort -nk1 | tac | column -t
@gargolito
gargolito / ssl_snippets
Last active December 30, 2019 22:58
ssl stuff #openssl #linux
convert cert downloaded from digicert to base64
openssl x509 -inform DER -in DigiCertSHA2SecureServerCA.crt -out DigiCertSHA2SecureServerCA.cer
Verify CA against SSL
openssl verify -verbose -CAfile DigiCertSHA2SecureServerCA.cer server.pem
Check that key matches cert, md5 output should be excatly the same if good.
openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in privateKey.key | openssl md5
@gargolito
gargolito / aws python json parsing.txt
Created September 13, 2019 17:16
aws python json parsing
# list available instance reservations
for k,v in d.items():
for r in v['ReservedInstances']:
if int(str(datetime.datetime.strptime(r['End'], '%Y-%m-%dT%H:%M:%S.000Z') - datetime.datetime.now()).split(',')[0].split(' ')[0]) > 0:
print(k, r['End'], r['InstanceCount'], r['InstanceType'])
@gargolito
gargolito / hydrogen_kernel_pyenv.txt
Created August 30, 2019 17:50
Atom Hydrogen Kernels with pyenv
in MacOs, hydrogen looks at /Users/<USER>/Library/Jupyter/kernels/python3/kernel.json for its kernel but when you are using pyenv and you install a kernel with ipykernel, it the kernel.json file is stored in /usr/local/share/jupyter/kernels/python3/kernel.json
The solution is to copy or symlink the installed kernel.json to where hydrogen expects the file to be:
ln -sf /usr/local/share/jupyter/kernels/python3/kernel.json /Users/<USER>/Library/Jupyter/kernels/python3/kernel.json
You'll have to re-start atom.