Skip to content

Instantly share code, notes, and snippets.

View peterfriese's full-sized avatar
🔥

Peter Friese peterfriese

🔥
View GitHub Profile
@peterfriese
peterfriese / Publisher+handleEvents.swift
Last active March 23, 2022 16:26
Make it easier to perform side effects (such as toggling a progress view) in a Combine pipeline. See this Twitter conversation for context: https://twitter.com/DonnyWals/status/1506330967941820423
extension Publisher {
/// Performs the specified closures when publisher events occur.
///
/// This is an overloaded version of ``Publisher/handleEvents(receiveSubscription:receiveOutput:receiveCompletion:receiveCancel:receiveRequest:)``
/// that only accepts a closure for the `receiveOutput` events. Use it to inspect events as they pass through the pipeline.
///
/// - Parameters:
/// - receiveOutput: A closure that executes when the publisher receives a value from the upstream publisher.
/// - Returns: A publisher that performs the specified closures when publisher events occur.
@peterfriese
peterfriese / MediumArticleApp.swift
Last active March 2, 2022 06:27 — forked from haIIux/MediumArticleApp.swift
Firebase Initialization - Swift
import SwiftUI
import Firebase
@main
struct MediumArticleApp: App {
init() {
FirebaseApp.configure()
}
@peterfriese
peterfriese / View+InteractiveDismissDisable.swift
Last active April 10, 2024 06:44
This is an enhanced version of Apple's `interactiveDismissDisabled` view modifier which allows you to act on the user's attempt to dismiss a sheet. See my article for more details. I filed a feedback for a feature request to add this to SwiftUI: FB9782213 (https://openradar.appspot.com/FB9782213)
import SwiftUI
extension View {
public func interactiveDismissDisabled(_ isDisabled: Bool = true, onAttemptToDismiss: (() -> Void)? = nil) -> some View {
InteractiveDismissableView(view: self, isDisabled: isDisabled, onAttemptToDismiss: onAttemptToDismiss)
}
public func interactiveDismissDisabled(_ isDisabled: Bool = true, attemptToDismiss: Binding<Bool>) -> some View {
InteractiveDismissableView(view: self, isDisabled: isDisabled) {
attemptToDismiss.wrappedValue.toggle()
@peterfriese
peterfriese / ReminderList
Last active November 9, 2021 08:30 — forked from disc0infern0/ReminderList
a Reminder List with control of focus, adding new values with double click, auto deleting nil values, using Combine for delay
//
// ReminderList.swift
//
// Demonstrates:-
// list settings (style, colouring etc )
// autoscrolling
// control of focus in List,
// adding new values with enter, or double click,
// auto deleting nil values,
// using Combine for managed delay/UI updates
@peterfriese
peterfriese / Color+Codable.swift
Created March 19, 2021 11:00
Making Swift's Color codable
//
// Color+Codable.swift
// FirestoreCodableSamples
//
// Created by Peter Friese on 18.03.21.
//
import SwiftUI
// Inspired by https://cocoacasts.com/from-hex-to-uicolor-and-back-in-swift
@peterfriese
peterfriese / GPG and git on macOS.md
Created November 27, 2020 16:55 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
import SwiftUI
class AppState: ObservableObject {
@Published var counter = 0
}
struct ContentView: View {
@EnvironmentObject var state: AppState
@State var presentDetailsView = false
@State var presentDetailsViewNoEnvironment = false
@peterfriese
peterfriese / MainActivity.java
Created January 28, 2014 15:22
Google+ PlusClient cross-platform connection sequence misorder?
package com.example.app;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
@peterfriese
peterfriese / UIViewController.h
Created November 30, 2011 20:54
Do I need to call didMoveToParentViewController in my custom container view controller? Yes, you do, the doc says it
// Taken from UIViewController.h, code is (c) Apple
/*
These two methods are public for container subclasses to call when transitioning between child
controllers. If they are overridden, the overrides should ensure to call the super. The parent argument in
both of these methods is nil when a child is being removed from its parent; otherwise it is equal to the new
parent view controller.
addChildViewController: will call [child willMoveToParentViewController:self] before adding the
child. However, it will not call didMoveToParentViewController:. It is expected that a container view
@peterfriese
peterfriese / gist:1267775
Created October 6, 2011 15:55
The Eysholdt Filter
var eysholdtFilter = new SimpleFilter(function(data) {
session = data;
session.abstract = session.abstract.replace(/<\/br>\n<\/br>\n/g, "\n");
session.abstract = session.abstract.replace(/<\/b>/g, "</b>");
session.abstract = session.abstract.replace(/<br>\n/g, "\n");
session.abstract = session.abstract.replace(/<\/br>\n/g, "\n");
return session;
});