Skip to content

Instantly share code, notes, and snippets.

@withakay
withakay / doubly_linked_list.py
Created November 8, 2022 16:28
Doubly Linked List 2 ways in python
from typing import Optional
from typing_extensions import Self
class Node:
def __init__(self, value: Optional[any] = None):
self.prev: Optional[Self] = None
self.next: Optional[Self] = None
self.value: any = value
@withakay
withakay / source-env.sh
Created September 8, 2022 09:43
Source from .env (dotenv) file
# if you want to export a .env file
# with a list of key values like
#
# `FOO=BAR`
#
# without prefixing them with `export` e.g.
#
# `export FOO=BAR`
#
# Do the following:
@withakay
withakay / deprecated_checker.py
Last active March 16, 2022 22:39
pylint deprecation checker
from astroid.nodes import Call, ClassDef, FunctionDef, Name, node_classes
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
def register(linter) -> None:
linter.register_checker(DeprecatedChecker(linter))
class DeprecatedChecker(BaseChecker):
@withakay
withakay / windows-vpn.ps1
Created December 11, 2019 16:20
Windows VPN
# Path for the public phonebook. Used as this is an all users connection.
# Change $env:PROGRAMDATA to $env:APPDATA if not creating an AllUserConnection.
$PbkPath = Join-Path $env:PROGRAMDATA 'Microsoft\Network\Connections\Pbk\rasphone.Pbk'
# Update these variables with the actual VPN name, address, and PSK.
$ConnectionName = 'ArrayString0',"ArrayString1", "ArracyString3","ArracyString4"
$ServerAddress = 'meraki-dynamic-ip-address-dynamic-m.com','meraki-dynamic-ip-address-dynamic-m.com','meraki-dynamic-ip-address-dynamic-m.com','meraki-dynamic-ip-address-dynamic-m.com'
$PresharedKey = 'PreSharedKeySecret'
# If no VPNs, rasphone.Pbk may not already exist
@withakay
withakay / commit-msg
Created December 21, 2021 14:31
prepend Jira ticket numbers to commit messages
#!/bin/bash
#
# .git/hooks/commit-msg is run when the -m flag is used
#
# Will extract Jira style ticket numbers from branch names e.g.
# 'AB-123-my-cool-branch' --> '[AB-123]'
# 'feature/XZ-321-my-cool-branch' --> '[XZ-321]'
#
TICKET=[$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")]
if [[ $TICKET == "[]";then
@withakay
withakay / install-latest-docker-compose.sh
Created February 8, 2021 06:51
Install the latest docker-compose
#!/bin/bash
# A script that will always install the latest docker-compose.
# Execute as root.
#
# See official docs for more
# https://docs.docker.com/compose/install/
#
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
@withakay
withakay / resize.sh
Last active February 4, 2021 17:11
Extend/Resize a partition and logic volume on Ubuntu Linux that was installed with LVM enabled
#!/usr/bin/env bash
# This script will extend the logical volume
# To use all the free space.
# Run this after increasing the size of the virtual disk.
# NOTE, run as sudo.
# Run `pvdisplay` to check your device numbers match up
# /dev/sda3 & ubuntu-vg & ubuntu-lv are the defaults
# if you chose LVM when installing Ubuntu
@withakay
withakay / dhcpd.conf
Created December 2, 2020 14:58
Update Route53 from ISC DHCP Server when a new lease is created via python and boto3
# add to dhcpd.conf
# make sure the dhcpd user has permission to execute the script
on commit {
set ClientName = pick-first-value(option fqdn.hostname, option host-name, "unknown-hostname");
set ClientIp = binary-to-ascii(10, 8, ".", leased-address);
set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
execute("/opt/dhcpd-hooks/dhcp_event_hook.py", "commit", ClientName, ClientIp, ClientMac);
}
@withakay
withakay / sigred_temp_fix.bat
Created July 17, 2020 11:28
SigRed temp registry fix
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNS\Parameters" /v "TcpReceivePacketSize" /t REG_DWORD /d 0xFF00 /f && net stop DNS && net start DNS
@withakay
withakay / NTLM.cs
Created October 8, 2019 08:34
NTLM Hash function in c#
/*
source:
https://www.codeproject.com/Articles/328761/NTLM-Hash-Generator
*/
public static string Ntlm(string key)
{
const uint INIT_A = 0x67452301;
const uint INIT_B = 0xefcdab89;
const uint INIT_C = 0x98badcfe;