This file contains 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 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 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 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 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 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 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 RxCocoa | |
import RxSwift | |
import UIKit | |
extension Reactive where Base: UIView { | |
var isFirstResponder: Observable<Bool> { | |
return Observable | |
.merge( | |
methodInvoked(#selector(UIView.becomeFirstResponder)), | |
methodInvoked(#selector(UIView.resignFirstResponder)) |
This file contains 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
public func descendants<Descendant>(of parent: Descendant, in attribute: KeyPath<Descendant, [Descendant]>, where: (Descendant) throws -> Bool) rethrows -> [Descendant] { | |
var descendants: [Descendant] = [] | |
for child in parent[keyPath: attribute] { | |
if try `where`(child) { | |
descendants.append(child) | |
} | |
try descendants.append(contentsOf: MASCore.descendants(of: child, in: attribute, where: `where`)) | |
} | |
return descendants | |
} |
This file contains 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 parse from 'obj-parse' | |
/* | |
In its simplest usage, mapStateToProps('foo', 'bar') | |
maps the state keys 'foo' and 'bar' to keys of the same | |
name in the props. | |
To alias, use an object literal: mapStateToProps('foo', {baz: 'bar.buzz'}). | |
In this case, we're mapping state that's more deeply nested to the 'baz' prop. | |
The parse method of obj-parse takes care of this for us. |
This file contains 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
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RecordWildCards #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TupleSections #-} |