Skip to content

Instantly share code, notes, and snippets.

View tnibert's full-sized avatar

Timothy Nibert tnibert

View GitHub Profile
@tnibert
tnibert / shelltricks.sh
Created August 22, 2022 00:10
shell tricks
# get all lines between two timestamps in a log
sed -n '/2012-08-20 11:34/,/2012-08-22 16:34/p' file
@tnibert
tnibert / certbotnotes.sh
Created June 13, 2022 05:10
Notes on certbot usage
certbot delete --cert-name example.com
@tnibert
tnibert / seeallevt.js
Created May 31, 2022 07:12
Find all js events fired for given object
function seeAllEvt(myObj) {
for(var key in myObj){
if(key.search('on') === 0) {
myObj.addEventListener(key.slice(2), function (e) {
console.log(e.currentTarget + " " + e.type);
});
}
}
}
@tnibert
tnibert / hashmapexample.rs
Created December 10, 2021 10:32
Rust hashmap example usage code
// hashmap example - for reference
let mut sample: HashMap<String, i32> = HashMap::new();
sample.insert("one".to_string(), 1);
sample.insert("two".to_string(), 2);
sample.insert("three".to_string(), 3);
sample.insert("four".to_string(), 4);
for (key, value) in sample.iter() {
println!("{} - {}", key, value);
}
@tnibert
tnibert / pipinstall.py
Created May 13, 2021 04:49
pip install from python 2 console
from pip._internal import main
pkg = "numpy" # example
main(['install', pkg])
@tnibert
tnibert / subnetcheck.py
Created February 25, 2021 08:33
Check if an address is in a given subnet
#! /usr/bin/env python3
split_fields = lambda addr: [int(f) for f in addr.split(".")]
def check_subnet(prefix_addr: str, prefix_length: int, to_check: str):
"""
Determine if the IPv4 address to_check is within the given subnet
:param prefix_addr: address prefix as shown in CIDR notation
:param prefix_length: the number of bits in the network section
@tnibert
tnibert / reduce_implementation.py
Last active January 25, 2021 23:12
Recursive reduce implementation with test
#! /usr/bin/env python3
def reduce2(func, ls):
if len(ls) == 1:
return ls[0]
return func(reduce2(func, ls[:-1]), ls[-1])
# test
testset = [1, 2, 3, 4, 5]
@tnibert
tnibert / find_big_files.sh
Created September 24, 2020 01:39
Identify large files
#!/bin/bash
# identify all files larger that 1 GB
find / -xdev -type f -size +1G -exec ls -lah {} \;
@tnibert
tnibert / helloworld-win32-service.py
Created July 8, 2020 12:25 — forked from drmalex07/helloworld-win32-service.py
An example Windows service implemented with pywin32 wrappers. #python #windows-service #pywin32
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import logging
logging.basicConfig(
filename = 'c:\\Temp\\hello-service.log',
@tnibert
tnibert / pyuac.py
Created July 8, 2020 12:24 — forked from Preston-Landers/pyuac.py
pyuac - elevate a Python process with UAC on Windows
#!/usr/bin/env python
# -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vim: fileencoding=utf-8 tabstop=4 expandtab shiftwidth=4
"""User Access Control for Microsoft Windows Vista and higher. This is
only for the Windows platform.
This will relaunch either the current script - with all the same command
line parameters - or else you can provide a different script/program to
run. If the current user doesn't normally have admin rights, he'll be