Skip to content

Instantly share code, notes, and snippets.

@pytlv
pytlv / reArrangeColumns.ts
Last active November 4, 2024 17:25
Office Scripts - Excel - reorder columns based on header row
/*
2024-04-10
Office Scripts - Excel - reorder columns based on header row
This script checks if the header row is in the correct order. If not, it rearranges the columns to match the order.
The order is defined in the order array.
Instructions:
1. Create a new Excel workbook for this example, assuming name is Sheet1.
2. Enter some data in the columns.
3. Create a new worksheet and name it "Sheet1_order".
# Kindall - https://stackoverflow.com/questions/8315389/how-do-i-print-functions-as-they-are-called
def tracefunc(frame, event, arg, indent=[0]):
if event == "call":
indent[0] += 2
print("-" * indent[0] + "> call function", frame.f_code.co_name)
elif event == "return":
print("<" + "-" * indent[0], "exit function", frame.f_code.co_name)
indent[0] -= 2
return tracefunc
@pytlv
pytlv / decorators.py
Created December 4, 2023 17:05
Python wrapper function to monitor execution time
# source: Sadrach Pierre https://builtin.com/data-science/python-wrapper
from functools import wraps
def runtime_monitor(input_function):
@functools.wraps(input_function)
def runtime_wrapper(*args, **kwargs):
start_value = time.perf_counter()
return_value = input_function(*args, **kwargs)
end_value = time.perf_counter()
runtime_value = end_value - start_value
@pytlv
pytlv / gist:f7fc5f20e9eddae5c740350defcbcc94
Created November 20, 2023 15:59
add last_modified column to an sqlite3 database
ALTER TABLE your_table
ADD COLUMN last_update TEXT;
CREATE TRIGGER update_last_update
AFTER UPDATE
ON Your_Table_Name
FOR EACH ROW
BEGIN
UPDATE Your_Table_Name
SET last_update = CURRENT_TIMESTAMP
@pytlv
pytlv / ufw_allow_israel_incoming.sh
Created July 31, 2022 18:39
UFW Script to allow all incoming connection from Israel IP Addresses
#!/bin/bash
echo "================UFW SCRIPT Start====================="
# IP List for Israel is based on:
# https://www.nirsoft.net/countryip/il.html
#### Recommendeda allow Web Server
#ufw allow 80
# Recommended to add your server's IP address
@pytlv
pytlv / ssmtp.conf
Created July 31, 2022 10:12
Namecheap ssmtp configuration
==================
#1 Edit the following file
/etc/ssmtp/ssmtp.conf
==================
#2 File should look like:
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.