Styles
Saturday, June 24, 2023
Presenting about Quarkus at the Java Meet Up
Quarkus is a framework designed for Kubernetes to improve the startup time and memory footprint of Java apps running in docker containers
Monday, June 12, 2023
Recursive CTE to List Years Without Gaps
If I have a requirement to list the years from a start year incrementing to the current year without any gap years, I can write the following simple SELECT statement within a CTE.
WITH FINANCIAL_YEARS AS (
SELECT 2020 AS FINANCIAL_YEAR
UNION SELECT 2021
UNION SELECT 2022
UNION SELECT 2023
)
However its pretty easy to see how tedious this can be especially when trying to maintain it when a new year ticks over.
I found this neat trick using recursive CTEs to avoid gaps in dates and tweaked it to deal with year increments:WITH FINANCIAL_YEARS AS (
SELECT '2020-01-01'::DATE AS YEAR_DATE
UNION ALL
SELECT DATEADD(YEAR, 1, YEAR_DATE) AS YEAR_DATE
FROM FINANCIAL_YEARS
WHERE YEAR_DATE < DATEADD(YEAR, -1, DATEADD(MONTH, 6, CURRENT_DATE())
)
SELECT DATE_PART(YEAR, YEAR_DATE) AS FINANCIAL_YEAR FROM FINANCIAL_YEARS
Its even simpler if you only want the year component or any other kind of numeric increment from a starting number:
WITH FINANCIAL_YEARS AS (
SELECT 2020 AS FINANCIAL_YEAR
UNION ALL
SELECT FINANCIAL_YEAR + 1 AS FINANCIAL_YEAR
FROM FINANCIAL_YEARS
WHERE FINANCIAL_YEAR < YEAR(DATEADD(MONTH, 6, CURRENT_DATE()))
)
SELECT FINANCIAL_YEAR FROM FINANCIAL_YEARS
Thursday, December 1, 2022
Reporting on your After Hours using Git commit timestamps
Sometimes its hard to keep yourself accountable to the extra long hours you work, and most of the time you don't want to show off how late you've been working, but every now and then your manager would probably ask if you've been putting in the necessary hours.
If thats the case, git commits can give you a certain level of transparency provided you commit regularly.
The following bash script assumes you have all your git repositories cloned to a folder specified in GITFOLDER which should be updated to your local setup. It will run a simple "git log --author" command for a given USERNAME and list only the timestamps after the hours of 5pm to the hours of 6am:
If thats the case, git commits can give you a certain level of transparency provided you commit regularly.
The following bash script assumes you have all your git repositories cloned to a folder specified in GITFOLDER which should be updated to your local setup. It will run a simple "git log --author" command for a given USERNAME and list only the timestamps after the hours of 5pm to the hours of 6am:
#!/usr/bin/env sh
USERNAME="<username>"
GITFOLDER="${HOME}/dev"
cd ${GITFOLDER}
FOLDERS=$(ls)
while IFS= read -r FOLDER
do
cd "${GITFOLDER}/${FOLDER}"
TIME_LOGS=$(git log --author="${USERNAME}" | grep "Date:" | grep -E '\s1[7-9]+\:|\s2[0-3]+\:|\s0[0-6]+\:')
while IFS= read -r TIME_LOG
do
if [ ! -z "$TIME_LOG" ]
then
COMMIT_DATE=$(echo ${TIME_LOG} | sed -e "s/Date: //g")
echo "${COMMIT_DATE} ${FOLDER}"
fi
done <<< "${TIME_LOGS}"
done <<< "${FOLDERS}"
Subscribe to:
Posts
(
Atom
)
