Skip to content

Instantly share code, notes, and snippets.

View aperfect's full-sized avatar

Adam Perfect aperfect

View GitHub Profile
@igorcferreira
igorcferreira / DynamicNavigationDestinationLink.swift
Last active September 2, 2019 11:27
Small Playground content, showcasing the use of DynamicNavigationDestinationLink to display content from remote source on 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
}
@JohnSundell
JohnSundell / CrossPlatformImages.swift
Last active November 22, 2022 06:29
An easy way to make code that uses UIImage cross-platform between iOS/tvOS & macOS
// Either put this in a separate file that you only include in your macOS target
// or wrap the code in #if os(macOS) / #endif
import Cocoa
// Step 1: Typealias UIImage to NSImage
typealias UIImage = NSImage
// Step 2: You might want to add these APIs that UIImage has but NSImage doesn't.
extension NSImage {
@ajself
ajself / rotatable.swift
Last active May 27, 2024 12:11
Rotate UIViewControllers that conform to a protocol
/*
This is an update to an example found on http://www.jairobjunior.com/blog/2016/03/05/how-to-rotate-only-one-view-controller-to-landscape-in-ios-slash-swift/
The code there works, with some updating to the latest Swift, but the pattern isn't very Swifty. The following is what I found to be more helpful.
*/
/*
First, create a protocol that UIViewController's can conform to.
This is in opposition to using `Selector()` and checking for the presence of an empty function.
*/
@pronebird
pronebird / CLLocationCoordinate2D+Encodable.swift
Created July 4, 2017 09:46
Encode CLLocationCoordinate2D with Codable in Swift 4
import CoreLocation
extension CLLocationCoordinate2D: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(longitude)
try container.encode(latitude)
}
@igoratron
igoratron / EnahanceConf-notes.md
Last active March 7, 2016 11:27
My notes from EnhanceConf 2016

Designing for a hostile environment

Nat Buckley

Video: https://www.youtube.com/watch?v=WU4vDTxLIdE

tl;dr: think about what you're building and who you're building it for

Browser is a very hostile environment to program against because lots of things are outside of our control, the network connection, the browser/runtime environment, screen size, etc...

What does it mean then when we say "a site doesn't work"? It means you can't complete a task, the reason why you came to the website in the first place. There are multiple reasons why that could be:

@tmilos
tmilos / README.md
Last active May 13, 2024 02:36
Modified Preorder Tree Traversal

Modified Preorder Tree Traversal

Hierarchical data metrics that allows fast read operations on tree like structures.

Based on Left and Right fields that are set during tree traversal. When entered into node value is set to it's Left, when exiting node value is set to it's Right.

Sample implementation

##Create a migration
### rails g migration make_unicode_friendly
class MakeUnicodeFriendly < ActiveRecord::Migration
def change
alter_database_and_tables_charsets "utf8", "utf8_general_ci"
end
private
def alter_database_and_tables_charsets charset = default_charset, collation = default_collation
@christianp
christianp / gist:10852696
Last active August 29, 2015 13:59
Fix multiple spaces in em tags containing three or fewer words
html.css('em,strong').each do |e|
if e.content.split.length <= 3
e.search('//text()').each do |n|
if ends_with_space
n.content = n.text.gsub(/^\s/,"\u00A0")
end
n.content = n.text.gsub(/(?<=[\s\u00A0])\s/,"\u00A0")
ends_with_space = n.text.match(/\s$/)
end
end
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
git clone git://github.com/wbond/sublime_package_control.git Package\ Control
cd Package\ Control
git checkout python3
# restart Sublime Text 3 and you should have Package Control working