Skip to content

Instantly share code, notes, and snippets.

View ap's full-sized avatar

Aristotle Pagaltzis ap

View GitHub Profile
@ap
ap / re-rfc-restful-secondary-key-api.md
Created August 13, 2022 18:06
Re: RFC: Restful Secondary Key API

Theory asks:

In any event, as far as I can tell this is a unique design, so maybe it’s too weird or not properly RESTful? Would love to know of any other patterns designed to solve the problem of supporting arbitrarily-named secondary unique keys. What do you think?

Not that unique. 🙂 And it really has nothing to do with representational state transfer.

This is purely URL design (i.e. purely a server-side concern). So on that note, let’s take a look at the good RFC:

Aside from dot-segments in hierarchical paths, a path segment is considered opaque by the generic syntax. URI-producing applications often use the reserved characters allowed in a segment to delimit scheme-specific or dereference-handler-specific subcomponents. For example, the semicolon (";") and equals ("=") reserved characters are often used to delimit parameters and parameter values applicable to that segment. The com

@ap
ap / Horrible.pm
Last active November 1, 2020 09:33
Wantarray::Horrible
package Wantarray::Horrible;
sub new {
my ( $class, $wantarray, $sub ) = ( shift, shift, shift );
; $wantarray ? bless [ &$sub ], __PACKAGE__.'::List'
: defined $wantarray ? bless \( scalar &$sub ), __PACKAGE__.'::Sclr'
: bless \do { &$sub; my $o }, __PACKAGE__.'::Void';
}
sub Wantarray::Horrible::List::value { @{ $_[0] } }
sub Wantarray::Horrible::Sclr::value { ${ $_[0] } }
sub Wantarray::Horrible::Void::value { () }
@ap
ap / foo.pl
Last active May 11, 2017 21:21 — forked from anonymous/foo.pl
use v5.10;
use re 'eval';
my @a = (
[ 'aaa', sub { say 'Apple' } ],
[ 'bbb', sub { say 'Banana' } ],
[ 'ccc', sub { say 'Carrot' } ],
);
my @r = map {
@ap
ap / toggle-finder-desktop.sh
Last active April 29, 2016 20:17
Toggle MacOS Finder desktop icons on/off
#!/bin/sh
( defaults read com.apple.finder CreateDesktop 2>/dev/null || echo 1 ) | egrep -qxi '1|true|yes|on'
defaults write com.apple.finder CreateDesktop $? && killall Finder
@ap
ap / scan-perl-prereqs-cpanfile
Created December 28, 2015 07:55
Shoddy dzil-free cpanfile generator cloned from the Dist::Zilla::Plugin::AutoPrereqs logic
#!/usr/bin/env perl
use strict;
use warnings;
use lib ();
use File::Find;
use List::Util qw{ max };
use Perl::PrereqScanner;
diff -urd --unidirectional-new-file orig/jpegtran.c droppatch/jpegtran.c
--- orig/jpegtran.c 2015-12-27 12:11:58.000000000 +0000
+++ droppatch/jpegtran.c 2014-03-26 11:52:18.000000000 +0000
@@ -37,6 +37,7 @@
static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */
+static char * dropfilename; /* for -drop switch */
static char * scaleoption; /* -scale switch */
static JCOPY_OPTION copyoption; /* -copy switch */
@ap
ap / faster-header-utils-bench.pl
Last active August 29, 2015 14:14
Pull request benchmarks for Plack#495
#!/usr/bin/env perl
use 5.012;
use warnings;
use Benchmark 'cmpthese';
use lib 'lib';
use Plack::Util ();
BEGIN { *header_iter = \&Plack::Util::header_iter }
@ap
ap / DynamicURLMap.pm
Created January 23, 2015 16:33
Plack::App::DynamicURLMap
use strict;
use warnings;
package Plack::App::DynamicURLMap;
use parent 'Plack::App::URLMap';
use Carp ();
use Scalar::Util ();
sub unmount { shift->unmap( @_ ) }
@ap
ap / spindown.sh
Created April 20, 2014 12:33
Spin down unused ATA disks on Linux
#!/bin/sh
echo -n 'Spinning down unused ATA drives:'
/usr/bin/lsscsi | /bin/grep -w -F ATA | /bin/cut -c54- \
| while read dev ; do
if /bin/mount | /bin/grep -q -E "^$dev[^/]* " ; then continue ; fi
echo -n " $dev,"
/sbin/hdparm -q -Y "$dev"
done
echo ' done.'
@ap
ap / Smart Maximize.applescript
Last active December 29, 2015 02:09
Takes the frontmost window, maximises it vertically, and centres it horizontally if it was off-screen
tell application "Finder"
set {dx1, dy1, dx2, dy2} to bounds of window of desktop
end tell
set cur_app to (path to frontmost application as Unicode text)
tell application cur_app
set {x1, y1, x2, y2} to bounds of front window
if x1 < dx1 or x2 > dx2 then
set displayWidth to dx2 - dx1