Skip to content

Instantly share code, notes, and snippets.

Avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
View CloudKitAccountStatus.swift
import CloudKit
import Combine
/// Fetches the user's CloudKit Account status.
///
/// - Parameter container: The container to check the status in.
///
/// - Returns: A deferred future that resolves to the user's CloudKit Account status.
func getAccountStatus(for container: CKContainer) -> AnyPublisher<CKAccountStatus, Error> {
Deferred {
@krzysztofzablocki
krzysztofzablocki / mac-list-bug.swift
Last active Apr 5, 2021
Why isn't last delete refreshing the list? Mac example
View mac-list-bug.swift
@main
struct ListBugApp: App {
var body: some Scene {
WindowGroup {
NavigationView { // comment out navigation view and list works
ContentView()
Text("Detail")
}
}
}
View SharedMutableState.swift
// Copyright (c) 2021 Manuel Maly
// 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
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
@krzysztofzablocki
krzysztofzablocki / process.sh
Created Jan 18, 2021
3rd party tooling processing script
View process.sh
#!/bin/zsh
cd "$(dirname "$0")/.."
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then
FAIL_ON_ERRORS=true
echo "Running in --fail-on-errors mode"
ERROR_START=""
COLOR_END=""
INFO_START=""
@krzysztofzablocki
krzysztofzablocki / FindFinalClasses.swift
Last active Sep 9, 2020
Swift makes classes final if possible
View FindFinalClasses.swift
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.attributes["final"] != nil || type.attributes["open"] != nil || types.based[type.name]?.isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g"
<% } %>
View something.swift
button.onTouchUpInside(context: self) { context in
// doStuff
}
@krzysztofzablocki
krzysztofzablocki / template.stencil
Last active Jan 14, 2017
AutoEquatable template
View template.stencil
// swiftlint:disable file_length
fileprivate func compareOptionals<T>(lhs: T?, rhs: T?, compare: (_ lhs: T, _ rhs: T) -> Bool) -> Bool {
switch (lhs, rhs) {
case let (lValue?, rValue?):
return compare(lValue, rValue)
case (nil, nil):
return true
default:
return false
View Capture.swift
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func perform(initial: Int) {
var value: Int = initial
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue()) { [myConstant = value] in
print("constant in first block \(myConstant)")
print("captured \(value)")
value = initial * 2
View UINavigationItem+KZAdditions.h
@import UIKit;
@interface UINavigationItem (KZAdditions)
@property (nonatomic, copy) NSDictionary *kz_titleTextAttributes;
@end
View gist:f5f597f04b2efcb711c7
require 'mechanize'
require 'moving_average'
mechanize = Mechanize.new
login_page = mechanize.get 'https://www.myfitnesspal.com/account/login'
form = login_page.forms.first
# noinspection RubyResolve
form.field_with(id: 'username').value = "username"
form.field_with(id: 'password').value = "pass"
form.submit