Skip to content

Instantly share code, notes, and snippets.

View wiljdaws's full-sized avatar

Dawson J. Williams wiljdaws

View GitHub Profile
@wiljdaws
wiljdaws / krabby_patty.ps1
Created June 7, 2024 12:36
rick roll and shutdown
Add-Type -TypeDefinition @'
using System.Runtime.InteropServices;
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioEndpointVolume {
int f(); int g(); int h(); int i();
int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext);
int j();
int GetMasterVolumeLevelScalar(out float pfLevel);
}
@wiljdaws
wiljdaws / set_volume.ps1
Created June 7, 2024 12:01
turns volume up 100%
Add-Type -TypeDefinition @'
using System.Runtime.InteropServices;
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioEndpointVolume {
int f(); int g(); int h(); int i();
int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext);
int j();
int GetMasterVolumeLevelScalar(out float pfLevel);
}
@wiljdaws
wiljdaws / endpoint.py
Created November 6, 2023 07:55
Crawl endpoints for any website quickly!
import scrapy
from tabulate import tabulate
import os
class EndpointSpider(scrapy.Spider):
name = 'endpoint-spider'
base = 'wikipedia' # <-------- base of url you want to crawl
start_urls = [f'https://www.{base}.com']
def __init__(self, *args, **kwargs):
@wiljdaws
wiljdaws / send_slacl.py
Created August 14, 2023 19:26
Send dictionary to slackbot
def send_to_slackbot(dictionary_object: dict, webhook_string: str):
'''
This function sends the dictionary object to the slackbot
Args:
- dictionary_object (dict): dictionary object
- webhook_string (str): webhook string
Raises:
ValueError: if response status code is not 200
Return type: None
@wiljdaws
wiljdaws / delete_empty_folders.py
Created August 14, 2023 19:23
Delete empty folders in path
import os
import logging
# if log folder does not exist create it
if not os.path.exists('main\log'):
os.makedirs('main\log')
logging.basicConfig(filename='main\log\deleted_folders.log',
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
@wiljdaws
wiljdaws / sep_logs.py
Last active August 14, 2023 19:16
Log error and info seperator
import re
import os
import logging
def read_error_log():
'''
Read weekly_hr.log file and create two new files:
1. errors.log - contains all errors
2. info.log - contains all info
@wiljdaws
wiljdaws / convert_txt_to_csv
Created August 14, 2023 19:06
Convert tab delimited file to csv good for dwp ETL txt exports.
import re
import os
import shutil
desktop_path = os.path.expanduser("~/Desktop")
downloads_path = os.path.expanduser("~/Downlaods")
# get username
username = os.getlogin()
def convert_to_csv(txt_file):
@wiljdaws
wiljdaws / post.py
Created August 9, 2023 19:23
Post Json Data
#! /usr/bin/env python3
import os
import requests
directory = "/data/feedback"
for filename in os.listdir(directory):
if filename.endswith(".txt"):
with open(os.path.join(directory, filename)) as file:
lines = file.readlines()
@wiljdaws
wiljdaws / create_requirements_file.py
Created August 6, 2023 23:11
Create a requirements.txt for the current environment
import pkg_resources
# List all installed packages and their versions
installed_packages = [f"{dist.project_name}=={dist.version}" for dist in pkg_resources.working_set]
# Write the package list to a requirements.txt file
with open("requirements.txt", "w") as requirements_file:
requirements_file.write("\n".join(installed_packages))
print("requirements.txt file generated.")
@wiljdaws
wiljdaws / scheduler.py
Created August 4, 2023 23:41
scheduler to run tasks
import time
import logging
import schedule
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
class AdvancedScheduler:
def __init__(self, start_time, end_time, interval):
self.start_time = start_time
self.end_time = end_time