Skip to content

Instantly share code, notes, and snippets.

View josepsmartinez's full-sized avatar

José Pedro Silveira Martinez josepsmartinez

View GitHub Profile
import requests
import io
import PyPDF2 # pip install PyPDF2
from seleniumwire import webdriver # pip install selenium-wire
def payload_from_gene_data(dataset: list[str], signature, cutoff_1, cutoff_2):
return {
'methodoption': 'os',
@josepsmartinez
josepsmartinez / install-pip.sh
Created October 2, 2022 09:37
Python: Manual pip install
#!/bin/bash
# https://pip.pypa.io/en/stable/installation/#get-pip-py
wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py &&\
python /tmp/get-pip.py
@josepsmartinez
josepsmartinez / force_removal.ps1
Created September 24, 2022 23:28
[Windows] Force removal of directory (Powershell 7.2)
# Run code below in a shell started by the following command
# to guarantee Administrator privileges
# Start-Process powershell -Verb runAs
function Control-Item-Cmd {
param($InputObject)
$InputObjectPath = $InputObject.fullname
$GrantArg = "{0}:(F)" -f $env:USERNAME
@josepsmartinez
josepsmartinez / cmd_attr.bat
Last active September 8, 2022 09:48
Windows .bat: attributing command output to variable (solution from https://stackoverflow.com/a/48404829/4449273)
FOR /F "tokens=* USEBACKQ" %%g IN (`<command>`) do (SET <variable name>=%%g)
#!/bin/bash
h=$(whereis -f cudnn.h | cut -f2 -d' ')
MAJOR=$(cat $h | grep CUDNN_MAJOR | head -n 1 | cut -f3 -d ' ')
MINOR=$(cat $h | grep CUDNN_MINOR | head -n 1 | cut -f3 -d ' ')
PATCHLEVEL=$(cat $h | grep CUDNN_PATCHLEVEL | head -n 1 | cut -f3 -d ' ')
echo "$MAJOR.$MINOR.$PATCHLEVEL"
@josepsmartinez
josepsmartinez / apt-reload
Last active July 21, 2022 17:47
Bash script to be put on a superuser priviliged binaries directory, like: /sbin or /usr/sbin (as in https://askubuntu.com/a/308048)
#!/bin/bash
apt update &&\
apt upgrade &&\
apt autoremove
@josepsmartinez
josepsmartinez / exhaust_iterator.py
Created June 12, 2022 23:52
Exhaust Python iterator
# as in https://stackoverflow.com/a/36763172/4449273
import collections
def exhaust_iterator(it):
collections.deque(it, maxlen=0)
@josepsmartinez
josepsmartinez / install_python_src.sh
Last active June 7, 2022 17:23
Install Python from source (Debian systems)
RELEASE_URL=https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz
wget ${RELEASE_URL} -O Python-src.tgz && tar xzf Python-src.tgz &&\
cd Python-src &&\
./configure --enable-optimizations --with-openssl=$(which openssl) &&\
sudo make altinstall &&\
rm -rf Python-src Python-src.tgz
@josepsmartinez
josepsmartinez / timestamp.py
Last active May 10, 2022 17:41 — forked from wzpan/timestamp.py
Python datetime timestamps
import datetime
# ISO formatting
datetime.datetime.utcnow() # ('2022-05-10 04:18:09.297644')
datetime.datetime.now() # ('2022-05-10 01:18:09.297743')
# Custom formatting
## Pretty ('Saturday, 15. December 2012 11:19AM')
datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
## Calendar ('2012-12-15')
@josepsmartinez
josepsmartinez / gcloud-zone_of_instance.sh
Created April 27, 2022 00:29
gcloud zone of instance
# https://techoverflow.net/2019/04/01/how-to-find-zone-of-google-cloud-vm-instance-on-command-line/
gcloud compute instances list --filter='name="${INSTANCE_NAME}"' --format 'get(zone)' | rev | cut -d/ -f1 | rev