on_exit_2

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
import atexit
import sqlite3

cxn = sqlite3.connect("db.sqlite3")


def init_db():
    cxn.execute("CREATE TABLE IF NOT EXISTS memes (id INTEGER PRIMARY KEY, meme TEXT)")
    print("Database initialised!")


@atexit.register
def exit_handler():
    cxn.commit()
    cxn.close()
    print("Closed database!")


if __name__ == "__main__":
    init_db()
    1 / 0
    ...

on_exit_1

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
import atexit


@atexit.register
def exit_handler() -> None:
    print("We're exiting now!")


def main() -> None:
    for i in range(10):
        print(2**i)


if __name__ == "__main__":
    main()
    atexit.unregister(exit_handler)
    1 / 0

deprecated

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
# XXX
# XXX TALK ABOUT PEP 702
# XXX https://peps.python.org/pep-0702
# XXX

from deprecated import deprecated


@deprecated("Adding ain't cool no more", version="1.0.0")
def add(x: int, y: int) -> int:
    return x + y


if __name__ == "__main__":
    print(add(5, 7))

timing

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
import time
from time import perf_counter, sleep
from functools import wraps
from typing import Callable, Any


def get_time(func: Callable) -> Callable:
    @wraps(func)
    def wrapper(*args, **kwargs) -> Any:

        # Note that timing your code once isn't the most reliable option
        # for timing your code. Look into the timeit module for more accurate
        # timing.
        start_time: float = perf_counter()
        result: Any = func(*args, **kwargs)
        end_time

caching

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
import time
from functools import cache


@cache
def count_vowels(text: str) -> int:
    """
    A function that counts all the vowels in a given string.

    :param text: The string to analyse
    :return: The amount of vowels as an integer
    """
    vowel_count: int = 0

    # Pretend it's an expensive operation
    print(f'Bot: Counting vowels in: "{text}"...')
    time.sleep(2)

    # Count those damn vowels
    for letter in text:
        if letter in 'aeiouAEIOU':
  

retry

https://github.com/federicoazzu/five_decorators/ https://youtu.be/3_P-dxrNCq8?si=Znfh3SA2YtIEGYzg
import time
from functools import wraps
from typing import Callable, Any
from time import sleep


def retry(retries: int = 3, delay: float = 1) -> Callable:
    """
    Attempt to call a function, if it fails, try again with a specified delay.

    :param retries: The max amount of retries you want for the function call
    :param delay: The delay (in seconds) between each function retry
    :return:
    """

    # Don't let the user use this decorator if they are high
    if ret

在鼠标指向窗口周围画矩形

 POINT pnt;
 RECT rc;
 HWND DeskHwnd = ::GetDesktopWindow();    //取得桌面句柄
 HDC DeskDC = ::GetWindowDC(DeskHwnd);     //取得桌面设备场景
 int oldRop2 = SetROP2(DeskDC, 10);
 ::GetCursorPos(&pnt);                //取得鼠标坐标
 HWND UnHwnd = ::WindowFromPoint(pnt);    //取得鼠标指针处窗口句柄
 HWND g_hWnd = UnHwnd;
 ::GetWindowRect(g_hWnd, &rc);      //获得窗口矩形
 if (rc.left < 0) rc.left = 0;
 if (rc.top < 0) rc.top = 0;
 HPEN newPen = ::CreatePen(0, 3, RGB(0, 200, 0));    //建立新画笔,载入DeskDC
 HGDIOBJ oldPen = ::Sele

CFolderPickerDialog 文件夹选择对话框示例

// 文件夹选择(目录选择)对话框示例
CFolderPickerDialog fd;
fd.m_ofn.lpstrTitle = _T("选择 dm.SetPath 设置的全局路径");
if (fd.DoModal() == IDOK) {
    GetDlgItem(ID_EDIT_DMSETPATH)->SetWindowText(fd.GetPathName());
}

MFC CFileDialog 示例

// 打开文件
CFileDialog fd(TRUE, _T(".dll"), NULL);
fd.m_ofn.lpstrTitle = _T("选择dm.dll文件");
fd.m_ofn.Flags &= ~OFN_ALLOWMULTISELECT;
if (fd.DoModal() == IDOK) {
    GetDlgItem(IDC_DM_DLL)->SetWindowText(fd.GetPathName());
}

Validate Password in Javaascript

 function validatePassword(password = "") {
  let regex1 = /(?=.*[A-Z])/; // check that the password must contain at least one uppercase English character.
  let regex2 = /(?=.*[a-z])/; // check that the password must contain at least one lowercase English character.
  let regex3  = /(?=.*\d)/; // check that the password must contain at least one digit.
  let regex4 = /(?=.*[!@#$%^&*()\-+.])/; // check that the password must contain at least one special character from the [!@#$%^&*()\-+.].

Deal Sheet - Bill To Companies

SELECT
  DISTINCT RTRIM(dbo.dmbill.bi_name) AS bi_name,
  dbo.dmbill.bi_id,
  RTRIM(dbo.dmbill.bi_street) AS bi_street,
  RTRIM(dbo.dmbill.bi_city) AS bi_city,
  RTRIM(dbo.dmbill.bi_state) AS bi_state,
  RTRIM(dbo.dmbill.bi_zip) AS bi_zip,
  RTRIM(dbo.dmgrp.gr_name) AS BillingGroup,
  RTRIM(dbo.dmbill.bi_contact) AS bi_contact,
  RTRIM(dbo.dmbill.bi_phone) AS bi_phone,
  rep.RepName,
  pipedrive.d2_value AS PipedriveDealID,
  mindate.mo_date AS BillToCreatedDate
FROM
  dbo.dttord

生活在今天的密封舱里

1871年春天,一个年轻人看到一本书,里面有一句话对他的前途产生了巨大的影响。他是蒙特瑞医院的一个学生。他
当时正满怀忧虑,担心如何通过期末考试、要做什么、到哪里去,怎样才能开业、才能谋生等。

如今他已成为当时最有名的医学家,他创造了闻名世界的约翰·霍普斯金斯医学院,成为牛津大学的客座教授,并被英
王册封爵位。他的后半生无忧无虑,需要上千页的书才能记述他的一生。

他的名字叫做威廉·奥斯勒爵士。他在1871年春天看到的那句由汤姆斯·卡莱里所写的话,帮助他度过了无忧无虑的一
生,这句话就是:"对我们来说,首先要做的事情不是去观望遥远的将来,而是做手边的清晰之事。"

42年之后,在一个温暖的春夜,郁金香开满了校园,威廉·奥斯勒爵士正在对耶鲁大学的学生发表演讲。他对那些耶鲁
大学的学生们说,像他这样一位曾经在四所大学当过教授、写过一本很受欢迎的书的人,似乎应该有一个"特殊的头
脑",其实不然。他说,他的一些好朋友都知道,他的脑筋其实"最普通不过了"。

那么他成功的秘诀到底是什么呢?他认为,这完全是因为他生活在一个"只有今天的密封舱"里。他这句话是什么意思?

生活在今天的密封舱里

1871年春天,一个年轻人看到一本书,里面有一句话对他的前途产生了巨大的影响。他是蒙特瑞医院的一个学生。他
当时正满怀忧虑,担心如何通过期末考试、要做什么、到哪里去,怎样才能开业、才能谋生等。

如今他已成为当时最有名的医学家,他创造了闻名世界的约翰·霍普斯金斯医学院,成为牛津大学的客座教授,并被英
王册封爵位。他的后半生无忧无虑,需要上千页的书才能记述他的一生。

他的名字叫做威廉·奥斯勒爵士。他在1871年春天看到的那句由汤姆斯·卡莱里所写的话,帮助他度过了无忧无虑的一
生,这句话就是:"对我们来说,首先要做的事情不是去观望遥远的将来,而是做手边的清晰之事。"

42年之后,在一个温暖的春夜,郁金香开满了校园,威廉·奥斯勒爵士正在对耶鲁大学的学生发表演讲。他对那些耶鲁
大学的学生们说,像他这样一位曾经在四所大学当过教授、写过一本很受欢迎的书的人,似乎应该有一个"特殊的头
脑",其实不然。他说,他的一些好朋友都知道,他的脑筋其实"最普通不过了"。

那么他成功的秘诀到底是什么呢?他认为,这完全是因为他生活在一个"只有今天的密封舱"里。他这句话是什么意思?

UAT Test | prev_initial_default_or_payoff

select fn.loan_id, 
	fn.installment_number as ins_n, 
	fn.period_start as p_strt, 
	fn.period_end as p_end,  
	fn.amount_owed_to_period as owed_to_prd,
	fn.amount_paid_to_period as paid_to_prd,
	fn.initial_default_cumulative as int_dft,
	fn.early_payoff_cumulative as e_payff_cum,
	fn.refinance_payoff_cumulative as r_payff_cum,
	fn.prev_initial_default_or_payoff
from dw_core.fact_installment fn
where fn.loan_id = 650229
order by fn.installment_number;

select fn.loan_id, 
	fn.installment_number a

Открыть туннелирование через SSH

#/etc/ssh/sshd_config

AllowTcpForwarding yes
GatewayPorts yes

systemctl restart ssh

Collect All Members of On-Call Groups

A quick and dirty script to get all the members of on-call groups which can be further parsed in Excel
// 1. Get all on-call shifts's unique groups
var gr = new GlideRecord('cmn_rota');
gr.query();

var uniqueGroupsArray = []; 

while (gr.next()) {
    var group = gr.group + '';
    if (uniqueGroupsArray.indexOf(group) == -1) {
        uniqueGroupsArray.push(group);
    }
}

gs.info('On-Call Groups: ' + uniqueGroupsArray.length);
// 2. Get all unique group's unique users
var uniqueUsersArray = [];

for (var i=0;i<uniqueGroupsArray.length;i++) {
    var grUsers = new GlideRecord(