Skip to content

Instantly share code, notes, and snippets.

/**
* Converts a number to A,B,C,...,X,Y,Z,AA,AB,AC,...,ZZ,AAA,AAB, etc.
*
* @param int $int must be at least 1
* @return string
*/
function spreadsheetLetters(int $int): string {
if ($int < 0) throw new TypeError('$int must be at least 0');
$numeric = $int % 26;
@jkoop
jkoop / git-blame-count.sh
Last active May 2, 2023 19:47
Who gets blamed for the most lines in a git project?
#! /bin/sh
git ls-files -z | \
xargs -0n1 git blame -w | \
grep -o --binary-files=text '^[^(]*([^)]*)' | \
grep -o '([^0-9]*' | \
grep -o '[^(]*' | \
sed 's/\s*$//g' | \
sort -f | \
uniq -c | \
@jkoop
jkoop / gitlab-burndown.php
Last active May 31, 2022 19:26
Burndown chart for GitLab milestones with basic tier
<!-- https://gist.github.com/jkoop/afc386f5742c2b61bf9657577b974449 -->
<?php if (isset($_GET['access_token']) && isset($_GET['project_id']) && isset($_GET['milestone_name'])) : ?>
<meta http-equiv="refresh" content="3600"> <!-- refresh every 1 hour -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/chart.js@^3"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@^2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation@^1/dist/chartjs-plugin-annotation.min.js"></script>
@jkoop
jkoop / human-readable-date-time.php
Last active March 23, 2022 14:19
Human-readable date/time for use in stuff like directory lists
<?php
// This is intended for use in stuff like directory lists
// 1234567890 unix time (input)
// 23:31:30 if today
// 13d 23:31 if this month
// Feb 13 23h if this year
// '09 Feb 13 if farther away
@jkoop
jkoop / split-media-by-chapters.sh
Last active September 30, 2022 01:37
use ffmpeg to split file by chapter metadata
#!/bin/bash
while [ $# -gt 0 ]; do
extension="${1##*.}"
ffmpeg -i "$1" 2> tmp.txt
# Chapter #0:0: start 0.000000, end 1290.013333
# first _ _ start _ end
while read -r first _ _ start _ end; do
@jkoop
jkoop / redlinks.js
Last active March 6, 2022 01:28
Try each link on the page, and if it's dead, made it red
@-moz-document domain("iplayif.com") {
body {
background: black;
color: white;
}
:root {
--glkote-buffer-fg: #fff;
--glkote-buffer-bg: #222;
--glkote-buffer-reverse-fg: #222;
<?php
function relativeTime(int|float|string $time): string {
static $minute = 60;
static $hour = 60 * 60;
static $day = 24 * 60 * 60;
static $month = 30 * 24 * 60 * 60;
static $year = 365 * 24 * 60 * 60;
if (!is_numeric($time)) {
#include <math.h> // gcc -lm enumerateFactorsOfN.c
int enumerateFactorsOfN(int n) {
int factors = 1;
double sqrtN = sqrt(n);
int n2 = (int) sqrtN;
for (int i = 1; i <= n2; i++) {
if (n % i == 0) {
factors++;
@jkoop
jkoop / ClosureTable.php
Last active September 20, 2021 20:04 — forked from mohanklein/ClosureTable.php
Closure Table Trait for Laravel Eloquent Models
<?php // app/Http/Traits/ClosureTable.php
namespace App\Models\Traits;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\Db;
/**