Skip to content

Instantly share code, notes, and snippets.

import UIKit
extension CGRect {
public static var unbounded: CGRect {
return CGRect(origin: .zero, size: .unbounded)
}
public var center: CGPoint {
return CGPoint(x: midX, y: midY)
}
@marksands
marksands / OptionalDateValue.swift
Created September 11, 2020 15:53
An Optional DateValue for BetterCodable, by duplicating existing types :P
public protocol OptionalDateValueCodableStrategy {
associatedtype RawValue: Codable
static func decode(_ value: RawValue?) throws -> Date?
static func encode(_ date: Date?) -> RawValue?
}
@propertyWrapper
public struct OptionalDateValue<Formatter: OptionalDateValueCodableStrategy>: Codable {
@marksands
marksands / Menu.swift
Last active April 21, 2022 18:13
AppKit NSMenu Helper
import AppKit
public struct MenuHotKeyPress: ExpressibleByStringLiteral {
public let character: String
public let modifierKeys: NSEvent.ModifierFlags?
public init(stringLiteral value: String) {
character = value
modifierKeys = nil
}
@marksands
marksands / timelapse.sh
Created September 6, 2014 04:17
Timelapse screen capture
while true ; do sleep 15 && echo `date`‘ Capturing screenshot…’ && screencapture -C -m -t jpg -x -f cap.`date +%s`.jpg ; done
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"More" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor lightGrayColor];
UITableViewRowAction *blurAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Blur" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];

Keybase proof

I hereby claim:

  • I am marksands on github.
  • I am marksands (https://keybase.io/marksands) on keybase.
  • I have a public key ASCiHMudz2diWLv9Nu36oOAK8MPoacliJ3oPi89JfulWngo

To claim this, I am signing this object:

struct PerformActionSideEffect<Output, Failure: Error> {
private let publisher: AnyPublisher<Output, Failure>
init<P: Publisher>(_ publisher: P) where P.Output == Output, P.Failure == Failure {
self.publisher = publisher.eraseToAnyPublisher()
}
@discardableResult
func performSink(_ action: @escaping (Output) -> Void) -> PerformActionSideEffect {
publisher.subscribe(
@marksands
marksands / 1_playground.swift
Last active December 9, 2019 03:06
Advent of Code 2019 Day 8 Vision Detection
import PlaygroundSupport
import UIKit
import Foundation
import Vision
func part2layer() -> [String] {
let layers = Array(input).chunks(ofSize: 25 * 6)
var picture = Array(repeating: "2", count: 25 * 6)
layers.forEach { layer in
enum Direction {
case up, down, left, right
}
protocol PositionType {
var x: Int { get }
var y: Int { get }
}
func euclideanDistance(_ lhs: PositionType, _ rhs: PositionType) -> Double {
@marksands
marksands / variadic_demo.cpp
Created May 31, 2012 06:06
Variadic Templates in C++11
#include <vector>
#include <algorithm>
// -----------------------------------------------------------------------------
// Function Object - print()
// -----------------------------------------------------------------------------
namespace eds {
template <typename T>
struct print : public std::unary_function<T, void> {