Skip to content

Instantly share code, notes, and snippets.

View plam4u's full-sized avatar
🏠
Working from home

Plamen Andreev plam4u

🏠
Working from home
View GitHub Profile
@jayrhynas
jayrhynas / CustomKeyCodable.swift
Last active February 25, 2021 16:23 — forked from IanKeen/CustomKeyCodable.swift
PropertyWrapper: CustomKeyCodable allows defining the keys for decoding _per property_
protocol CustomKeyCodable: Codable {
static var keyEncodingStrategy: ([CodingKey]) -> CodingKey { get }
static var keyDecodingStrategy: ([CodingKey]) -> CodingKey { get }
init()
}
extension CustomKeyCodable {
init(from decoder: Decoder) throws {
self.init()
@IanKeen
IanKeen / Example_Complex.swift
Last active January 23, 2024 07:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false
@vogler
vogler / Artillery-Genius.md
Last active December 27, 2023 12:48
Artillery Genius Config

image

Software

  • Mainboard firmware: Marlin 2.0.9.2 (fork with config, see Marlin/Configuration{,_adv}.h)
    • diff: nvim -d {Marlin,config/Artillery/Genius}/Configuration.h, same for Configuration_adv.h
      • mostly calibration, new extruder and noise-free PWM for parts fan
      • LIN_ADVANCE instead of S_CURVE_ACCELERATION (don't work together)
    • before 13.11.2020: Marlin 2.0.5.3 (3dprintbeginner) (branch)
  • TFT firmware: artillery_tft_fw_1.27.x_patch_9.2 (digant@thingiverse) (TFT-config.ini)
    • Put in Marlin mode (long press, persists on reboot) when printing with OctoPrint because TFT shares serial connection.
@IanKeen
IanKeen / Publisher+Result.swift
Created July 14, 2020 17:18
Extension to convert a failable Publisher into a non-failable Result based publisher (as well as extensions to break out values/errors) - Same idea as RxSwifts Materialize
extension Publisher {
func asResult() -> AnyPublisher<Result<Output, Failure>, Never> {
return map(Result.success)
.catch { Just(Result.failure($0)) }
.eraseToAnyPublisher()
}
}
extension Publisher {
func values<S, F: Error>() -> AnyPublisher<S, Never> where Output == Result<S, F>, Failure == Never {
@IanKeen
IanKeen / EntryPoint.swift
Last active August 17, 2023 03:33
Example main.swift
import Foundation
import SwiftUI
let isUITesting = /* your UI test detection here */
@main
struct EntryPoint {
static func main() {
if isUITesting {
UITestApp.main()
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@leoiphonedev
leoiphonedev / UITapGesture.swift
Last active November 28, 2023 12:45
Extension for UITapGesture that contains a function to detect range of particular text in UILabel's text.
extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool {
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: CGSize.zero)
let textStorage = NSTextStorage(attributedString: label.attributedText!)
// Configure layoutManager and textStorage
layoutManager.addTextContainer(textContainer)
@mitchellporter
mitchellporter / README.md
Created May 30, 2019 16:44 — forked from acrookston/README.md
Xcode pre-action to build custom Info.plist

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.

@edwinlee
edwinlee / Code.gs
Last active February 21, 2024 10:43
Sync a Google Sheets spreadsheet to a Firebase Realtime database
/**
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
function getEnvironment() {
var environment = {
spreadsheetID: "<REPLACE WITH YOUR SPREADSHEET ID>",
firebaseUrl: "<REPLACE WITH YOUR REALTIME DB URL>"
};
@ocrampete16
ocrampete16 / pipeline.py
Created March 5, 2019 00:22
A Python implementation of the Pipeline pattern
class Pipeline:
def __init__(self, value):
self.value = value
self.pipes = []
def through(self, pipe):
self.pipes.append(pipe)
def now(self):
for pipe in self.pipes: