Skip to content

Instantly share code, notes, and snippets.

@nmichlo
nmichlo / xterm_control_sequences.py
Last active January 27, 2024 15:12
XTerm Control Sequences
# XTerm Control Sequences based on:
# - https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
# ========================================================================= #
# XTerm Control Sequences from invisible-island.net as pythonic code.
# Basic control sequences are string variables.
# - eg: ESC = '\033'
# CSI = ESC + '['
# Control sequences that have args can be called to return a string.
# - eg: sgr = CSI + Ps + 'm'
@robb
robb / Example.m
Last active January 9, 2024 14:38
A macro to convert nullable references to nonnull references while triggering an assert if the expression is actually true. Think of this as unsafe unwrap for Objective-C.
NS_ASSUME_NONNULL_BEGIN
void Log(NSString *foo) {
NSLog(@"%@", foo);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *stuff = @{
@"a": @"Test"
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@andrewroycarter
andrewroycarter / Cocoapods Environment.md
Last active August 17, 2023 10:44
Directions on installing chruby, ruby, ruby-build, and bundler.

Setting up a good cocoapods environment

Before you start

Make sure that you have the latest version of Xcode installed from the Mac App Store, and that you have the command line tools installed. To install the command line tools, open Xcode, click Xcode->Preferences->Downloads->Command Line Tools

Install brew if needed.

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@hmlongco
hmlongco / Themes.swift
Last active January 10, 2023 06:54
Themes for SwiftUI
struct Colors {
let primary: Color
}
struct Fonts {
let body: Font
}
class Theme: ObservableObject {
let color: Colors
@czottmann
czottmann / Format current file with swiftformat.scpt
Last active December 30, 2022 19:04
Xcode helper: SwiftFormat the currently focussed doc w/o losing undo history
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- # This script formats the currently open and focussed Swift file
-- # using SwiftFormat. It does so *without* resetting the editor's
-- # undo history.
-- #
-- # Version 2022-12-30.01
-- #
-- # Author: Carlo Zottmann
@humblehacker
humblehacker / kotlin-inject-composable-viewmodel.md
Last active March 17, 2022 13:56
Injecting view models into Composable functions with kotlin-inject

According to the docs, the non-DI way to associate an view model with an @Composable is via the viewModel() function from androidx.lifecycle.viewmodel.compose.viewModel, like this:

@Composable
fun ProfileScreen(val viewModel: ProfileViewModel = viewModel() {
  ...

But if your view model requires dependencies, you have to pass a subclass of ViewModelProvider.Factory that holds the dependency and knows how to construct the view model for you. Like this:

@humblehacker
humblehacker / Sequence_associateBy.swift
Created June 27, 2017 23:11
Swift 3 implementation of Kotlin's associateBy for transforming a Sequence to a Dictionary
public
extension Sequence
{
/// Returns a Dictionary using the result of `keySelector` as the key, and the result of `valueTransform` as the value
public func associateBy<T, K: Hashable, V>(_ keySelector: (T) -> K, _ valueTransform: (T) -> V) -> [K:V] where T == Iterator.Element
{
var dict: [K:V] = [:]
for element in self {
dict[keySelector(element)] = valueTransform(element)
}
@fitomad
fitomad / KeyboardResponder.swift
Created November 22, 2019 19:23
Manage iOS keyboard presentation and dismiss with your SwiftUI views.
//
// KeyboardResponder.swift
// MoveMAD
//
// Created by Adolfo Vera Blasco on 19/11/2019.
// Copyright © 2019 desappstre {eStudio}. All rights reserved.
//
import SwiftUI
@simonliotier
simonliotier / SwiftUI+CustomFonts+DynamicType.swift
Last active December 11, 2019 14:27
Example of how to get Dynamic Type with custom fonts in SwiftUI
import SwiftUI
/// Example of how to get Dynamic Type with custom fonts in SwiftUI.
struct ContentView: View {
var body: some View {
VStack(spacing: 20) {
Text("A large title").customFont(.largeTitle) // "Optima-ExtraBlack", 28
Text("A body").customFont(.body) // "Kailasa", 16
Text("A caption").customFont(.caption2) // "IowanOldStyle-Italic", 11
}