Skip to content

Instantly share code, notes, and snippets.

@Revolucent
Revolucent / Most.swift
Last active August 29, 2015 14:07
Minimum/maximum implementations for SequenceType and Arrays in Swift
/*
Replace the name of my Swift module, Prosumma, with your own, or this will not compile.
As of 1.0, Swift lacks mixins (as in Ruby) or the ability to extend protocols (as in C#), which means lots of
cumbersome boilerplate. I've tried to cut down on that with this little snippet. First, you'll notice that
there are no actual minimum and maximum functions defined. To achieve that, do the following:
var lowest: Int? = [5, 4, 3].most(<)
var highest: Int? = [5, 4, 3].most(>)
@Revolucent
Revolucent / sprintf.psql
Last active June 5, 2023 04:51
sprintf function for PostgreSQL with indexed arguments
-- Inspired by https://wiki.postgresql.org/wiki/Sprintf,
-- but really, pretty different.
CREATE FUNCTION sprintf(_format TEXT, VARIADIC _args ANYARRAY) RETURNS TEXT
LANGUAGE PLPGSQL
STRICT IMMUTABLE
AS $$
DECLARE _f INT DEFAULT 0; -- Index of current character in format string
DECLARE _c TEXT; -- Current character
DECLARE _match TEXT;
DECLARE _matches TEXT[];
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,