Skip to content

Instantly share code, notes, and snippets.

#########################
# .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,
@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[];
@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 / Unique.swift
Created October 9, 2014 15:38
Unique Extension Method For Swift SequenceTypes
/*
The reason this does not return a value is that SequenceType
is very general. It has no methods for modifying the sequence,
only traversing it.
Instead, we pass our "unique" method a closure that tells it
how to add a value to our result. The result is not visible
at all to this method. It is captured by our closure.
The reason we don't pass the result as a parameter is because it
@Revolucent
Revolucent / BitwiseOptions.swift
Last active September 22, 2018 12:46
BitwiseOptions implementation for Swift
//
// BitwiseOptions.swift
//
// Created by Gregory Higley on 11/24/14.
// Copyright (c) 2014 Prosumma LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@Revolucent
Revolucent / git-gat
Last active July 22, 2018 23:39
The Git Gatling Gun: Perform operations on multiple side-by-side git repositories.
#!/bin/bash
# Git Gat: The Git Gatling Gun!
# Perform operations machine-gun style on side-by-side git repositories.
#
# Save this somewhere on your path as git-gat (or whatever you want to call it).
# Usage:
#
# git gat status
# git gat -f status # Perform operation even if the repo is dirty.
@Revolucent
Revolucent / git-only
Last active August 29, 2015 14:21
git-only
#!/bin/bash
# Git Only: Perform a Git operation only when in a whitelisted directory.
#
# This is really only useful when combined with git-gat. For instance, let's
# say we want to create a branch in two of our side-by-side repos, we can say:
#
# git gat only Repo1 Repo2 -- checkout -b feature1
#
# This will create and checkout a branch called feature1, but only in Repo1 and Repo2.
@Revolucent
Revolucent / Resolver.swift
Created January 8, 2016 07:27
Poor Man's Dependency Resolver for Swift
enum CreationPolicy {
case Single
case Shared
}
class Resolver {
private struct Instance {
private let policy: CreationPolicy
private let create: () -> Any
private var instance: Any?
@Revolucent
Revolucent / DependencyResolver.swift
Last active July 9, 2019 22:49
DependencyResolver - a simple, elegant, flexible dependency resolver for Swift 2.x
//
// DependencyResolver.swift
//
// Created by Gregory Higley on 2/15/16.
// Copyright © 2016 Revolucent LLC.
//
// This file is released under the MIT license.
// https://gist.github.com/Revolucent/25daa75bda879dd20bb2
//
@Revolucent
Revolucent / UIColorExtensions.swift
Last active July 18, 2017 02:45
Convert a six-digit hex literal into a color
extension UIColor {
convenience init(hex: UInt, alpha: CGFloat = 1.0) {
let red = CGFloat((hex & 0xFF0000) >> 0x10) / 255.0
let green = CGFloat((hex & 0x00FF00) >> 0x8) / 255.0
let blue = CGFloat(hex & 0x0000FF) / 255.0
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
}