Skip to content

Instantly share code, notes, and snippets.

View ben-nour's full-sized avatar

Ben Nour ben-nour

View GitHub Profile
@ben-nour
ben-nour / automating_conda_python_script.md
Last active March 23, 2025 23:56
Automating conda Python script on an admin-locked Windows computer.
@ben-nour
ben-nour / inserting_none_into_snowflake.py
Created March 12, 2025 23:26
How to insert None objects into a Snowflake table's numeric column.
import snowflake.connector
value = None
# Won't work:
f"""INSERT INTO example_table(
visitors
) VALUES
(
'{value}',
@ben-nour
ben-nour / python_re_functions.py
Last active March 24, 2025 22:52
An overview of main functions from the Python re module.
"""
Good reference: https://www.dataquest.io/cheat-sheet/regular-expressions-cheat-sheet/
Official documentation: https://docs.python.org/3/library/re.html
"""
import re
text = "dog cat dog"
########## re.findall() ##########
@ben-nour
ben-nour / extract_fy.sql
Last active August 12, 2024 02:25
Snowflake UDF to extract FY from a date.
CREATE OR REPLACE FUNCTION extract_fy(date_to_convert varchar, date_format varchar DEFAULT 'YYYY-MM-DD')
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
SELECT
CASE
WHEN MONTH(TRY_TO_DATE(date_to_convert, date_format)) >= 7 THEN
CONCAT('FY', RIGHT(YEAR(TRY_TO_DATE(date_to_convert, date_format)) + 1, 2))
ELSE CONCAT('FY', RIGHT(YEAR(TRY_TO_DATE(date_to_convert, date_format)), 2))