Skip to content

Instantly share code, notes, and snippets.

View diraneyya's full-sized avatar

Orwa Diraneyya diraneyya

View GitHub Profile
@diraneyya
diraneyya / upcoming_previous_window_functions.sql
Last active May 5, 2025 10:16
previous() and upcoming() are window functions that retrieve the previous or the upcoming non-null value within a column in pgsql.
-- "s" stands for state, "v" stands for value, "sf" stands for state (transition) function
create or replace function sf_previous(s anyelement, v anyelement)
returns anyelement language sql immutable strict as $$
select v $$;
create or replace function sf_upcoming(s anyelement, v anyelement)
returns anyelement language sql immutable strict as $$
select s $$;
drop aggregate if exists previous(anyelement);
@diraneyya
diraneyya / coalesce_equal.sql
Last active May 5, 2025 08:14
`coalesce_equal(...)` is a PostgreSQL function that is similar to `coalesce`, but requires that all non-null arguments be equal for it to return the identical value, when not equal or all arguments are null, it returns null.
create or replace function coalesce_equal(variadic args anycompatiblearray)
returns anycompatible language sql immutable as $$
with all_args(arg) as (select unnest(args)), dist_args(count) as (
select count(distinct arg) filter (where arg is not null) from all_args
)
select arg from all_args, dist_args
where arg is not null and count = 1
limit 1
$$;
@diraneyya
diraneyya / mermaid.ipynb.md
Last active March 22, 2025 09:42
Use Mermaid Diagrams in your IPython (i.e. Jupyter) Notebooks

You can do this either by using a public service like https://mermaid.ink or while hosting your own mermaid server. I find the latter option to be better in the long run, both in the individual and the collective sense. Below are recipes for both.

Using mermaid.ink

Use the following function defintion in your Jupyter notebook:

import base64
from IPython.display import display_svg
from urllib.request import Request, urlopen
@diraneyya
diraneyya / opening.html
Last active February 5, 2025 19:47
Job Opening for an IT Engineer in Construction
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div><a href="https://gistpreview.github.io/?2cf125d77ee7881a21a5e91f44cbcd9e/opening.html">(top)</a></div>
<div><a href="https://shorturl.at/sMjQE">(home)</a></div>
@diraneyya
diraneyya / install_openmanage_proxmox.sh
Created December 4, 2024 12:02
Access iDRAC over a HTTPS (web UI) with Proxmox by installing the DELL OpenManage package on the Proxmox's Debian node system
#
# credit to `jonomoss`: https://www.youtube.com/watch?v=8QpCzaXBUI4
#
apt update
# This is up to you if you would like to apply all updates
apt upgrade
# These are the extra dependencies I needed
# You can see if you are successful without them
apt install gnupg libcurl4 libncurses5 libxslt1-dev libgpm2 libtinfo5
@diraneyya
diraneyya / fix-svn-export.sh
Created July 20, 2024 11:04
Fix workflows that used `svn export` to download a part of a repository from GitHub in 2024
if [ $# -ne 5 ] && [ $# -ne 4 ]; then
echo "Usage: `basename $0` <github_user> <github_repo> <branch> <dest_dir> [<repo_dir>]"
echo
echo "if <repo_dir> is omitted then the entire repo archive is unpacked into <dest_dir>"
exit 0
fi
DEST_DIR=./$4
SOURCE_URL=https://github.com/$1/$2/archive/refs/heads/$3.tar.gz
if [ $# -ne 5 ]; then

A COUNTRY CALLED GHANA

Ghana is a very peaceful but crazy place to live. Ghana is a country in the West Africa, where the people living in are black and are called Ghanaians. It was first named GOLD COST, because it was blessed with gold and was full of natural resources, Ghana gained her independence on 6th March 1957.

The first president to govern ghana was Osagyefo Dr Kwame Nkrumah. The common language spoken in ghana is English but the traditional or local language in ghana is Twi, there are many dishes in ghana but the best and popular dish in ghana is Fufu, fufu is a dish made from cassava and yam or plantain together, the ghanaian dance is called "Adowa", and the ghana popular costume is "Kente". Ghana is a country ruled with written constitution and every four years election takes place to select a new president. Ghana has many political parties but the most popular parties which has ruled the country for the past 24 years are National Democratic Congress (NDC) and New Patriotic Party

CREATIVE SOLUTIONS FOR FIRST NON-REPEATING CHARACTER DOJO

DOJO Links:

Solution by Manisha/Sveta, modified for case-insensitive test cases

checks if a character is non-repeating by looking for the 2nd match in a string and ensuring that this 2nd match exists. Based on String.prototype.indexOf (check the second usage in the Syntax section on MDN).

// Challenge one: Add all the numbers in array
array.reduce((a, e) => a + e);
// Challenge two: Create a string with all the numbers stitched in one string
array.join('')
array.reduce((a, e) => `${a}${e}`)
array.reduce((a, e) => '' + a + e);
array.reduce((a, e) => a + e.toString(), '');
array.reduce((a, e) => a + e, '');
array.reduce((a, e) => a.toString() + e.toString());
gantt
dateFormat  YYYY-MM-DD
title Example of how to add a GANTT diagram to README.md using mermaid in GitHub-flavoured markdown
excludes weekdays 2014-01-10

section A section
Completed task            :done,    des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d