Skip to content

Instantly share code, notes, and snippets.

@rgs
rgs / intersect.sh
Created March 15, 2024 12:20
Get the intersection of an arbitrary number of json files with jq
#!/usr/bin/env bash
function intersectJson {
echo $* | \
jq -nS '
def intersect:
.[0] as $a |
.[1] as $b |
if ($a | type) == "object" then
if ($b | type) == "object" then
@rgs
rgs / repositories-without-codeowners.sh
Last active February 28, 2024 14:43
Find all repositories without CODEOWNERS
#!/bin/bash
# This will output a CSV of all non-archived repositories in the
# specified organisation, and whether the CODEOWNERS file is here
# or not found. Also exclude forked repositories. A suitable token
# must be in the environment variable $GH_TOKEN.
ORGA=rgs
for repo in $( gh repo list $ORGA --json isArchived,isFork,name --limit 500 \
--jq '.[] | select(.isArchived == false) | select(.isFork == false) | .name' \
@rgs
rgs / conjuncts.pl
Created October 31, 2019 14:24
Shows all conjunct consonants in devanagari
#!perl
use 5.18.2;
use strict;
use warnings;
use open ':std', ':utf8';
print " | ";
for my $c (0x0915 .. 0x0939) {
print chr($c)." | ";
}
@rgs
rgs / wasted_memory.pl
Created April 30, 2014 10:40
A perl function to get the amount of wasted memory on a memcached server
sub wasted_memory {
my ($host, $port) = @_;
my @slabstats = `echo stats slabs | nc $host $port`;
my %perslab;
my $total_malloced = 0;
my $total_wasted = 0;
for (@slabstats) {
if (/STAT total_malloced ([0-9]+)/) {
$total_malloced = $1;
@rgs
rgs / gist:7370406
Created November 8, 2013 12:32
A vim status line item to display git branch name and status of the currently edited file. To be put in the ~/.vimrc.
" returns a string <branch/XX> where XX corresponds to the git status
" (for example "<master/ M>")
function CurrentGitStatus()
let gitoutput = split(system('git status --porcelain -b '.shellescape(expand('%')).' 2>/dev/null'),'\n')
if len(gitoutput) > 0
let b:gitstatus = strpart(get(gitoutput,0,''),3) . '/' . strpart(get(gitoutput,1,' '),0,2)
else
let b:gitstatus = ''
endif
endfunc

Falsehoods programmers believe about prices

  1. You can store a price in a floating point variable.
  2. All currencies are subdivided in 1/100th units (like US dollar/cents, euro/eurocents etc.).
  3. All currencies are subdivided in decimal units (like dinar/fils)
  4. All currencies currently in circulation are subdivided in decimal units. (to exclude shillings, pennies) (counter-example: MGA)
  5. All currencies are subdivided. (counter-examples: KRW, COP, JPY... Or subdivisions can be deprecated.)
  6. Prices can't have more precision than the smaller sub-unit of the currency. (e.g. gas prices)
  7. For any currency you can have a price of 1. (ZWL)
  8. Every country has its own currency. (EUR is the best example, but also Franc CFA, etc.)
@rgs
rgs / perldoc-wordcloud.pl
Created March 22, 2012 09:30
A script to create word clouds from perl's core documentation
use strict;
use warnings;
use File::Slurp;
use Image::WordCloud;
for my $file (<perl*.pod>) {
my $text = `pod2text $file`;
my $wc = Image::WordCloud->new();
$wc->words($text);
my $gd = $wc->cloud();
$file =~ s/od$/ng/;