Skip to content

Instantly share code, notes, and snippets.

View diraneyya's full-sized avatar

Orwa Diraneyya diraneyya

View GitHub Profile
@diraneyya
diraneyya / proxmosh.sh
Last active October 3, 2025 10:30
A jump script for the mobile shell (Mosh) when used to connect to Proxmox containers/VMs via its root PVE node
#!/usr/bin/env bash
# The public IP address or the Dynamic DNS hostname of the
# proxmox host, which can be resolved to a public IP address
PROXMOX_HOST=host.dyndns.org
# A single TCP port that is used for initiating a connection
PROXMOX_TCP_PORT=2222
# A range of UDP ports that can be used for each Mosh session
PROXMOX_UDP_PORTS=60001:60008
function numBusesToDestination(
routes: number[][],
source: number,
target: number
): number {
// 1 <= routes.length (n) <= 500.
// 1 <= routes[i].length (m) <= 10^5
// construct a hashmap for stops | O(m x n)

Dog Head Wound Care Instructions - Ghana

What to Buy at the Pharmacy

Ask for these exact names (all common in Ghana):

  1. Dettol Antiseptic Liquid (brown liquid in bottle - around 40-50 cedis for 250ml)
    • Also called "Dettol Liquid"
    • Most pharmacies have this
@diraneyya
diraneyya / README.md
Last active September 1, 2025 16:03
IGNORE NULL in first_value/last_value in PostgreSQL

Ignoring NULLs in PostgreSQL with first_value/last_value

In the SQL snippet below, you see custom aggregates that are similar to first_value/last_value but which ignore NULL values, making them more useful in my opinion.

-- "s" stands for state, "v" stands for value, "sf" stands for state (transition) function
-- since these are defined as 'strict', "s" is the previous, while "v" is the next, non-null
-- value in the defined window.

create or replace function sf_first_value_ignore_nulls(s anyelement, v anyelement)
@diraneyya
diraneyya / lesson_plan.md
Last active August 16, 2025 18:18
Triggers to prevent insertions, updates, and/or deletions on a table in PostgreSQL

Introduction

In relational databases, it is possible to request that the database engine executes a function when an event is about to take place within a table. The events that can trigger such a function are INSERT, UPDATE and DELETE.

In the case of triggers called before these operations, database engines give us an additional power: the power to intervene, and possibly prevent the operation from taking place.

This is the core concept of this lesson.

Trigger Syntax in SQL

@diraneyya
diraneyya / upcoming_previous_window_functions.sql
Last active September 1, 2025 11:52
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 $$;
create or replace aggregate previous(anyelement) (
@diraneyya
diraneyya / coalesce_equal.sql
Last active August 28, 2025 17:33
`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.
-- Similar to coalesce, but only gives back a non-null value if all the non-null
-- params are equivalent.
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 June 22, 2025 19:26
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