Skip to content

Instantly share code, notes, and snippets.

View ps1dr3x's full-sized avatar
👨‍💻
0x1A4

Michele Federici ps1dr3x

👨‍💻
0x1A4
View GitHub Profile
@ps1dr3x
ps1dr3x / get-cookie.js
Created March 28, 2017 15:09
Get cookie by name
@ps1dr3x
ps1dr3x / docker-cheatsheet
Last active October 7, 2020 14:23
Docker & docker-compose cheat sheet
# Remove all containers
docker rm $(docker ps -aq)
# Remove dangling images
docker rmi $(docker images -q -f dangling=true)
# Remove all images
docker rmi $(docker images -aq)
# Remove all the unused volumes
@ps1dr3x
ps1dr3x / check-page-for-keyword.sh
Last active February 20, 2018 15:58
Script for periodically check a web page for a keyword
#!/bin/sh
#
# Script for periodically (default: 10m) check a web page for a keyword
#
# Gist:
# https://gist.github.com/ps1dr3x/5a5697ea2d37d06a34fdb38ef36050d4
#
# Usage:
# check-for-page-keyword.sh host keyword [seconds]
#
@ps1dr3x
ps1dr3x / self-signed-cert-with-altnames.sh
Last active October 8, 2018 10:35
Create self-signed certificate with main details and altnames (one liner)
# Location of openssl.cnf might be different
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \
-subj "/C=IT/ST=BO/L=Bologna/O=Aperture Science SRL/CN=example.com" \
-extensions SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "\n[SAN]\nsubjectAltName=DNS:www.example.com,DNS:sub.example.com,IP:123.123.123.123")) \
-out example.crt -keyout example.key
@ps1dr3x
ps1dr3x / xset-led-wayland.sh
Created October 26, 2018 17:44
Turn on keyboard backlight/leds on wayland (xset led 3 alternative)
# "input0::scrolllock" might be different (?)
# On
sudo sh -c 'echo 1 > /sys/class/leds/input0::scrolllock/brightness'
# Off
# sudo sh -c 'echo 0 > /sys/class/leds/input0::scrolllock/brightness'
@ps1dr3x
ps1dr3x / increase-open-files-limit-linux.txt
Last active December 9, 2018 15:48
Increase open files limit (Linux)
Append this lines to /etc/security/limits.conf
* hard nofile 500000
* soft nofile 500000
root hard nofile 500000
root soft nofile 500000
Log-out and log-in and check new limits
Hard:
@ps1dr3x
ps1dr3x / hot-partition-resize
Created May 19, 2019 13:28
Hot partition resize
swapoff -a
fdisk /dev/xxx
# delete partitions partitionX + swap (d)
# create new primary partitions partitionX + swap (n + p) with the new size
# change parititon type (t) partitionX -> 83, swap -> 82
# add bootable flag (a) partitionX
# write changes (w)
partprobe
@ps1dr3x
ps1dr3x / receive.py
Last active December 3, 2022 20:19
Send and receive a file using python's HTTPServer to receive and curl or powershell to send
from os import curdir
from os.path import join as pjoin
from http.server import BaseHTTPRequestHandler, HTTPServer
class StoreHandler(BaseHTTPRequestHandler):
store_path = pjoin(curdir, 'file')
def do_POST(self):
if self.path == '/':
### Keybase proof
I hereby claim:
* I am ps1dr3x on github.
* I am ps1dr3x (https://keybase.io/ps1dr3x) on keybase.
* I have a public key ASAOMSkZS9IQcvRUMI58e-PMjmISJnxJepn4rY8KYj3-_wo
To claim this, I am signing this object:
@ps1dr3x
ps1dr3x / battery-charge-threshold.service
Last active July 5, 2022 08:46
systemd service to set a charge limit for the laptop's battery (when supported)
[Unit]
Description=Set the battery charge threshold
After=multi-user.target
StartLimitBurst=3
StartLimitIntervalSec=300s
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold'