This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import ReSwift | |
import RxSwift | |
private class StoreObserver<SelectedState>: StoreSubscriber { | |
private let onNext: (SelectedState) -> Void | |
init(onNext: @escaping (SelectedState) -> Void) { | |
self.onNext = onNext | |
} | |
func newState(state: SelectedState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator ??!: NilCoalescingPrecedence | |
/** | |
If the left-hand side in nil, the error on the right-hand side is thrown. Otherwise, | |
the unwrapped value is returned. For example: | |
``` | |
// Instead of this… | |
guard let x = y else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGContext { | |
// via https://stackoverflow.com/a/50419334/27779 | |
func drawSemicircle(from: CGPoint, to: CGPoint, clockwise: Bool) { | |
let center = CGPoint(x: 0.5 * (from.x + to.x), y: 0.5 * (from.y + to.y)) | |
let radius = 0.5 * hypot(to.x - from.x, to.y - from.y) | |
let startAngle = atan2(to.y - from.y, to.x - from.x) | |
let endAngle = startAngle + .pi | |
move(to: from) | |
addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://wiki.postgresql.org/wiki/Aggregate_Median | |
CREATE OR REPLACE FUNCTION _final_median(NUMERIC[]) | |
RETURNS NUMERIC AS | |
$$ | |
SELECT AVG(val) | |
FROM ( | |
SELECT val | |
FROM unnest($1) val | |
ORDER BY 1 | |
LIMIT 2 - MOD(array_upper($1, 1), 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
XCODE='Xcode'; | |
XCODEPATH="$(xcode-select -p)"; | |
if [[ $XCODEPATH =~ /([^/]+)\.app ]]; then | |
XCODE="${BASH_REMATCH[1]}" | |
fi; | |
open -a "$XCODE" "${1:-.}"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# The MIT License (MIT) | |
# | |
# Copyright (c) 2016 Gregory Higley (Prosumma) | |
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum CreationPolicy { | |
case Single | |
case Shared | |
} | |
class Resolver { | |
private struct Instance { | |
private let policy: CreationPolicy | |
private let create: () -> Any | |
private var instance: Any? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |