Skip to content

Instantly share code, notes, and snippets.

View marcoscholz's full-sized avatar

Marco Scholz marcoscholz

  • Gibraltar
  • 21:51 (UTC +02:00)
View GitHub Profile
@marcoscholz
marcoscholz / latest-sql-query-cheatsheet.md
Last active October 3, 2025 10:44
Latest Query for MySQL / MariaDB / Aurora / Postgres

Latest Query

for MySQL, MariaDB, AWS Aurora (MySQL), Postgres & AWS Aurora (Postgres)

Why it matters

  • A very common SQL problem everyone come to at some point is to get the latest or current entry over a given group.
  • It is often solve quite complex with GROUP BY and subqueries.
  • The objective of this GIST is to show a simple reuseable way to solve this specific problem.
    • It is very intuitve that the created index directly shows up in the PARTITION BY or ORDER BY statements
    • The query is very human-readable and easy to understand
@marcoscholz
marcoscholz / CircleArray.php
Last active August 9, 2023 09:05
Return Array values circular
<?php
class CircleArray
{
private static array $dataToLoop = ["one", "two", "three"];
private static int $index = 0;
public static function nextElement()
{
if(empty(static::$dataToLoop)) return null;
# https://www.baeldung.com/linux/delete-files-based-on-size
find . -type f -size +1G -exec rm-v {} \;
# Create a release commit and write version and release timestamp to a file
# The release tag will afterwards be moved to the new commit
name: Release Commit
on:
release:
types: [ created ]
jobs:
releaseJob:
@marcoscholz
marcoscholz / example.js
Last active February 14, 2022 23:49
fetch with timeout and handling
import {fetchTimeout} from './fetchTimeout.js';
const timeout = 1000;
let successCallback = response => console.info(response);
let timeoutCallback = error => console.error(`Account data couldn't be fetched. Aborted request after ${timeout} ms.`);
new fetchTimeout('/api/my/endpoint', successCallback, timeout).catch(timeoutCallback);
let tableSelector = `#myTable`;
let colName = `myColName`;
let dataTable = $(tableSelector).DataTable();
/** @link https://datatables.net/reference/api/column().search() */
let searchString = `.*(a|b).*`;
let isRegEx = true;
let smart = false; // disable if you use RegEx
let caseInsensitive = true; // default is true. Disable if you need case sensitive search
table.column(`${colName}:name`).search(searchString, isRegEx, smart, caseInsensitive).draw();
@marcoscholz
marcoscholz / count_log_errors.sh
Last active January 6, 2020 10:11
Counts errors from logfiles
#!/bin/bash
# http://httpd.apache.org/docs/2.0/logs.html
FILTER="PHP"
sed -e "s/\[.*\]\([^:]*\)\(.*\)/\1/" /var/log/apache2/error.log | grep $FILTER | sort | uniq -c