Skip to content

Instantly share code, notes, and snippets.

View backslash-f's full-sized avatar
💻
Keep calm and Swift

Fernando Fernandes backslash-f

💻
Keep calm and Swift
View GitHub Profile
@backslash-f
backslash-f / Playground.swift
Created January 14, 2020 08:43
typealias + Function with return value
import SwiftUI
typealias Filter = (CGImage) -> CGImage
func blur(radius: Double) -> Filter {
return { image in
// Do something.
return image
}
}
@backslash-f
backslash-f / .swiftlint.yml
Last active February 5, 2020 22:06
Gist for .swiftlint.yml
---
disabled_rules:
# Doesn't play nice with SwiftUI.
# https://github.com/realm/SwiftLint/issues/1801
- multiple_closures_with_trailing_closure
excluded:
- Carthage
# Variable name should be between 3 and 40 characters long...
@backslash-f
backslash-f / Network.swift
Created November 26, 2019 13:49
Check if the device is connected to a network
import SystemConfiguration
/// Returns `true` if the device is connected to a network, either WiFi or Cellular (4G, 5G, etc).
///
/// [source](https://stackoverflow.com/a/39782859/584548)
func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in(
sin_len: 0,
sin_family: 0,
sin_port: 0,
# sudo: auth account password session
auth sufficient pam_tid.so
auth sufficient pam_smartcard.so
auth required pam_opendirectory.so
account required pam_permit.so
password required pam_deny.so
session required pam_permit.so
@backslash-f
backslash-f / APIClient.swift
Last active August 22, 2019 21:02
Network / APIClient / REST abstraction in a Swift Playground
import Foundation
import PlaygroundSupport
/// Async.
PlaygroundPage.current.needsIndefiniteExecution = true
///
/// Movie Model Codable
///
struct MovieModel: Codable {
@backslash-f
backslash-f / UIDeviceExtension.swift
Last active December 9, 2022 14:26
Get Apple device model / marketing Name
import UIKit
public enum ModelName: String {
case simulator
case iPod1, iPod2, iPod3, iPod4, iPod5
case iPad2, iPad3, iPad4, iPad5, iPad6
case iPadAir, iPadAir2, iPadAir3
case iPadMini, iPadMini2, iPadMini3, iPadMini4, iPadMini5
case iPadPro9_7, iPadPro10_5, iPadPro12_9, iPadPro2_12_9, iPadPro11, iPadPro3_12_9
case iPhone4, iPhone4S
@backslash-f
backslash-f / README.md
Last active November 19, 2023 15:59
Sample on adding repo images and shields.io badges on README.md files

Image that is in the repo:

![Key Mapping](https://github.com/backslash-f/ShockEmu/blob/master/KeyMapping.png)

Or by path:

![Storyboard](Images/xcode-storyboard.png)
@backslash-f
backslash-f / NSMutableStringStrikeThrough.swift
Last active July 28, 2020 20:54
NSMutableString Playground - change portions of it based on custom tags
import Foundation
import UIKit
// Say you have a NSMutableString like "<strikeStartTag>+ 6.99<strikeEndTag>" and need to strike through "+ 6.99".
extension String {
func firstRange(from start: String, to end: String?) -> Range<String.Index>? {
guard let lower = range(of: start)?.upperBound else { return nil }
guard let end = end else { return lower..<self.endIndex }
guard let upper = self[lower...].range(of: end)?.lowerBound else { return nil }
@backslash-f
backslash-f / sublime-settings
Last active July 12, 2022 07:30
Gist for Sublime Settings
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.sublime-color-scheme",
"default_line_ending": "unix",
"dictionary": "Packages/Language - English/en_US.dic",
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": true,
"font_size": 17,
"gpu_window_buffer": false,
"ignored_packages":
[
@backslash-f
backslash-f / sublime-keymaps-user
Last active October 13, 2020 09:00
Gist for Sublime Key Bindings
[
{
"keys": ["super+enter"],
"command": "build"
},
{
"keys": ["super+shift+c"],
"command": "show_u200b"
},
{