Skip to content

Instantly share code, notes, and snippets.

View tnibert's full-sized avatar

Timothy Nibert tnibert

View GitHub Profile
@tnibert
tnibert / netcat.py
Created October 28, 2016 08:52 — forked from leonjza/netcat.py
Python Netcat
import socket
class Netcat:
""" Python 'netcat like' module """
def __init__(self, ip, port):
self.buff = ""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@tnibert
tnibert / CreateEncryptedDisk.sh
Created July 22, 2018 04:29
Create encrypted automounting disk on Linux
# wipe the disk
wipefs –a /dev/sda
parted /dev/sda mklabel gpt
parted /dev/sda mkpart logical ext4 0% 100%
mkdir /mnt/usb
cryptsetup luksFormat /dev/sda1 # type YES and then enter a password
dd if=/dev/urandom of=/root/keyfile bs=1024 count=4
chmod 0400 /root/keyfile
cryptsetup luksAddKey /dev/sda1 /root/keyfile #Enter passphrase
cryptsetup open /dev/sda1 encrypted
@tnibert
tnibert / fixmouse.sh
Created October 15, 2018 23:53
Fix Mouse Lockup in Linux
#! /bin/bash
# this tends to occur when I unplug a usb mouse
# cursor locks up, can click, can't move it - Xubuntu 18.10
# the following commands just reload the mouse module in the kernel
# fixes issue for the instance, yay
sudo modprobe -r psmouse
sudo modprobe psmouse
@tnibert
tnibert / getwinkey.ps
Created October 25, 2018 12:33
Get Windows key powershell script
# not made by me, but useful
$dpid = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "DigitalProductId"
# Get the range we are interested in
$id = $dpid.DigitalProductId[52..(52+14)]
# Character table
$chars = "BCDFGHJKMPQRTVWXY2346789"
# Variable for the final product key
@tnibert
tnibert / block-site-in-hosts-file
Created January 11, 2019 13:11
Block a website in /etc/hosts
0.0.0.0 www.example.com
0.0.0.0 example.com
::0 www.example.com
::0 example.com
@tnibert
tnibert / convertebook.sh
Created January 13, 2019 05:48
Convert epub to mobi
sudo apt-get install calibre
ebook-convert book.epub book.mobi
@tnibert
tnibert / trunc.py
Created April 10, 2019 01:42
Truncate n bytes from end of file
# truncate num_bytes off the end of a file
import os
def trunc(filename, num_bytes):
with open(filename, 'rb+') as fi:
fi.seek(-1 * num_bytes, os.SEEK_END)
fi.truncate()
@tnibert
tnibert / sigma.py
Last active May 4, 2019 23:33
Summation (sigma) notation in python 3
#! /usr/bin/env python3
#
# Σ i
# i=s
from functools import reduce
# the sequence to sum, you can use range(blah) as well
s = [1, 2, 3, 5]
@tnibert
tnibert / pdftricks.sh
Last active March 3, 2020 03:06
PDF shell manipulations
# this is a work in progress notepad, will include pdftk and ghostscript stuff
# replace page 13 of doc1.pdf with doc2.pdf
pdftk A=doc1.pdf B=doc2.pdf cat A1-12 B1 A14-end output out1.pdf
# remove the first 4 pages from in.pdf
pdftk A=in.pdf cat A5-end output out.pdf
# use ghostscript to combine PDFs
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf file1.pdf file2.pdf file3.pdf
@tnibert
tnibert / filldisk.sh
Created September 12, 2019 02:49
Fill a disk to 5 TB
# this will fill a disk to 5TB with one command, accounting for existing disk usage
# $a will be in kilobytes, so it must be converted in the expr to units of 150MB
# bs is set for efficiency, results on your disk may vary, if you change this, you'll need to change the number at the end in expr (currently 1024 * 150)
# the sed command specifies line 9 of the output pulled from df -k, you will need to change for your df output
dd if=/dev/zero of=/mnt/partition/bigfile bs=150MB count=$(let "a = 5368709120-`df -k | awk '{ print $3 "\t" }' | sed -n '9p'`"; expr $a / 153600)