Skip to content

Instantly share code, notes, and snippets.

View idrougge's full-sized avatar

Iggy Drougge idrougge

  • Stockholm, Sweden
View GitHub Profile
@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()
@IanKeen
IanKeen / Convertible.swift
Created April 24, 2020 16:57
PropertyWrapper: Convert to/from raw type during decoding/encoding
import Foundation
public protocol CodingStrategy {
associatedtype Converted
associatedtype RawValue: Codable
static func toRaw(_ value: Converted) throws -> RawValue
static func toValue(_ raw: RawValue) throws -> Converted
}
@danielmartin
danielmartin / XcodeNewBuildSystemSettings.json
Created February 23, 2020 14:37
Complete list of Xcode new build system settings and their documentation in JSON format.
This file has been truncated, but you can view the full file.
[
{
"spec": "com.apple.compilers.metal",
"path": "/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/Metal.xcplugin/Contents/Resources/Metal Compiler.xcspec",
"options": [
{
"name": "CLANG_DIAGNOSTICS_FILE"
},
{
"name": "MTLCOMPILER_DEPENDENCY_INFO_FILE"
#!/usr/bin/env xcrun -sdk macosx swift
// Displays UI in an NSWindow which can interact with the commandline
// Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift`
import Foundation
import SwiftUI
extension CommandLine {
static let input: String = { AnyIterator { readLine() }.joined() }()
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension Scanner {
// MARK: Strings
class ShapeShadowViewController: UIViewController {
var starView: UIView!
var roundedView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
starView = UIView()
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active May 10, 2024 15:05
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Jean-David Gadina - www.xs-labs.com
*
* 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
@DamnedScholar
DamnedScholar / language-sampleGrammar.cson
Last active January 25, 2023 20:14
Grammar boilerplate with annotations.
# TextMate tutorial: http://manual.macromates.com/en/language_grammars
# Regex to convert keys to unquoted: '(include|match|captures|begin|end|beginCaptures|endCaptures|name|patterns|0|1|2|3|4|5|6|7|8|9|comment|fileTypes|scopeName|repository|contentName|firstLineMatch|foldingStartMarker|foldingStopMarker)':
scopeName: 'source.<scope>' # <scope> should be a short, unique indicator for the language ("js", "php", "c", etc.)
name: '<name>' # The title that will show up in grammar selection and on your status bar.
fileTypes: [ # An array of file extensions.
'txt'
'exif'
]
@cabo
cabo / crlf.screenrc
Created December 19, 2015 13:33
Make GNU screen convert return key (CR) into CR-LF
# put this in your ~/.screenrc to make
# ^A D (uppercase) switch on, and
# ^A U (uppercase) switch off, converting
# CR (return keys) input into CRLF
bind D bindkey "\015" stuff "\015\012"
bind U bindkey "\015" stuff "\015"