Skip to content

Instantly share code, notes, and snippets.

View telmotrooper's full-sized avatar
🐧
➜ ~ echo "Hello, World\!" | lolcat

Telmo "Trooper" telmotrooper

🐧
➜ ~ echo "Hello, World\!" | lolcat
View GitHub Profile
@telmotrooper
telmotrooper / git-aliases.sh
Last active August 30, 2024 14:51
POSIX-compliant commands to automate common Git tasks
# Display commits from HEAD while counting them (useful for rebase).
alias gloc="git log --oneline --decorate --color | cat -n | less"
# Create a temporary branch squashing the changes of the current branch into another one.
function gcotb {
CURRENT_BRANCH=$(git branch --show-current)
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD --short | sed 's@^origin/@@')
if [ -n "$1" ] ;then
DEFAULT_BRANCH=$1
# Remap prefix from 'Ctrl + B' to 'Ctrl + A'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
@telmotrooper
telmotrooper / lse
Created May 21, 2019 19:22
ls separated by extensions
#!/usr/bin/bash
extensions=$(ls -l | awk '{print $9}' | cut -f 2-99 -d '.' | uniq)
for ext in $extensions
do
echo "-- $ext --"
ls -l | grep ".$ext" | awk '{print $9,$5}' | column -t -s " "
done
@telmotrooper
telmotrooper / https-server.py
Last active October 21, 2024 19:48
Simple HTTPS Server in Python 3 (updated to Python 3.13)
#!/usr/bin/env python3
# To generate a certificate use:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
from pathlib import Path
port = 4443
@telmotrooper
telmotrooper / batchRename.py
Created July 8, 2018 21:22
Batch file/folder renamer without regular expressions
from os import listdir, rename
from os.path import join, isdir
from readline import parse_and_bind
def main():
print("Batch Rename - Developed by Telmo H. V. Silva")
print("-" * 50)
parse_and_bind("control-v: paste")
@telmotrooper
telmotrooper / share_wifi.sh
Created May 26, 2018 19:23
Share your Wi-Fi connectiong through cable
# Based on tutorial at:
# https://null-byte.wonderhowto.com/how-to/share-your-laptops-wireless-internet-with-ethernet-devices-0130528/
# Bring your ethernet interface up and assign an IP to it
sudo ifconfig enp7s0 up
sudo ifconfig enp7s0 192.168.2.1
# Enable IPv4 forwarding
sudo echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward
class Sudoku:
"""Sudoku validator"""
grid = [[0] * 9 for i in range(9)]
def __init__(self):
self.populate_grid()
self.print_grid()
self.validate_grid()
@telmotrooper
telmotrooper / getpid.sh
Created April 30, 2017 23:19
Get Process ID by clicking on it
xprop _NET_WM_PID | cut -d' ' -f3
@telmotrooper
telmotrooper / wwwappender.py
Created April 30, 2017 22:57
Simple script to help appending the "www." prefix to entries in your hosts file
from shutil import copyfile
copyfile("in.txt", "out.txt")
inputFile = open("in.txt", "r")
outputFile = open("out.txt", "a")
outputFile.write("\n\n")
for line in inputFile.readlines():
@telmotrooper
telmotrooper / toggle_touchpad.sh
Last active May 28, 2018 13:01
Toggle touchpad script (recommended shortcut is "Ctrl + \")
#!/bin/bash
var=$(synclient -l | grep TouchpadOff)
if [[ "$var" == " TouchpadOff = 0" ]]; then
synclient TouchpadOff=1
else
synclient TouchpadOff=0
fi