Skip to content

Instantly share code, notes, and snippets.

View dave256's full-sized avatar

Dave Reed dave256

View GitHub Profile
@dave256
dave256 / TextExpander-JavaScript-snippet.js
Last active January 5, 2025 20:26
example TextExpander JavaScript snippet with fill-ins
// more info at this post: https://blog.dave256apps.com/2025/01/05/textexpander-javascript-snippets.html
function capitalizeFirstLetter(input) {
// Capitalize the first letter and append the rest of the string
return input.charAt(0).toUpperCase() + input.slice(1);
}
let filename = "%filltext:name=filename:width=20%";
let capitalizedFilename = capitalizeFirstLetter(filename);
let output = `#!/usr/bin/env python3
@dave256
dave256 / parser.swift
Last active December 3, 2024 23:29
AdventOfCode2024Day3Parser
struct IntPair: CustomStringConvertible {
let x: Int
let y: Int
var product: Int { x * y }
var description: String { "(\(x), \(y))"}
}
enum MulParser {
// modification of the sending example from @mattmassicotte's post here:
// https://www.massicotte.org/step-by-step-reading-from-storage
import SwiftUI
class DataModel {
var name: String
init(name: String) {
self.name = name
//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
@dave256
dave256 / PreferenceKeySizeExtensions.swift
Created April 1, 2021 21:48
use PreferenceKeys to make cells in a Stack/List/ForEach all have the same width/height
// Created by David M Reed on 4/1/21. (not an April Fool's joke)
// https://blog.dave256apps.com
// thanks to the talk.objc.io and swiftbysundell.com for inspiring these ideas with their content
import SwiftUI
typealias UpdateWidthFunction = ((CGFloat?) -> Void)
typealias UpdateHeightFunction = ((CGFloat?) -> Void)
typealias UpdateSizeFunction = ((CGSize) -> Void)
@dave256
dave256 / ContactCell.swift
Created January 16, 2021 01:01
ContactCell.swift
//
// ContactCell.swift
// ContactsCollectionView
//
// Created by David M Reed on 12/15/20.
//
import UIKit
class ContactCell: UICollectionViewListCell {
@dave256
dave256 / AddContactViewController.swift
Created January 16, 2021 00:12
version 1 AddContactViewController.swift
//
// AddContactViewController.swift
// ContactsCollectionView
//
// Created by David M Reed on 12/15/20.
//
import UIKit
class AddContactViewController: UIViewController {
//
// StatefulPreviewWrapper.swift
// Do It
//
// Created by Jim Dovey on 10/11/19.
// Copyright © 2019 Jim Dovey. All rights reserved.
//
import SwiftUI
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@dave256
dave256 / Decodable+URLSession.swift
Created November 26, 2020 21:15
Publisher for fetching Decodable from a URL
import Foundation
import Combine
struct APIError: Decodable, Error {
let statusCode: Int
}
// publisher code based on code in Practical Combine by Donny Wals
extension Decodable {
@dave256
dave256 / design.hpp
Created September 2, 2020 19:31
design question
#include <string>
class EmailAddress {
public:
EmailAddress(std::string name, std::string kind="home");
std::string address() const { return _email; }
std::string kind() const { return _kind; }
private:
std::string _email;