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 / 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 / .config
Last active October 19, 2023 20:39
Gist for neofetch .config
# See this wiki page for more info:
# https://github.com/dylanaraps/neofetch/wiki/Customizing-Info
#
# brew install neofetch
# mkdir ~/.config/neofetch
# touch config.conf
# pbpaste > config.conf
print_info() {
info title
@backslash-f
backslash-f / Shell.swift
Last active June 13, 2023 19:11
Invoke Zsh commands via a Swift script
#!/usr/bin/swift
import Foundation
func shell(_ command: String) {
let task = Process()
task.launchPath = "/bin/zsh"
task.arguments = ["-c", command]
let pipe = Pipe()
@backslash-f
backslash-f / Decodable.swift
Last active May 16, 2023 11:32
Swift Decodable example.
#!/usr/bin/swift
import Foundation
// TINY EXAMPLE
/*
let jsonData = Data(
"""
{
@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 / ClampingPlayground.swift
Last active September 7, 2022 09:26
Swift Clamping Example
import Foundation
import UIKit
/// Clamps the given `value` into the range defined by `minValue` and `maxValue`. For example:
///
/// (0.0 ... 5.0).clamp(4.2) = 4.2
/// (0.0 ... 5.0).clamp(-1.3) = 0.0
/// (0.0 ... 5.0).clamp(6.4) = 5.0
///
/// Source: https://stackoverflow.com/a/46799935/584548
@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 / heroku-pinger.sh
Last active February 3, 2022 08:14
Keeps Heroku servers awake
#!/bin/bash
# - Curls Heroku servers indicated in the "hosts" file.
# - Logs actions to log files (unique per host), including the response HTTP status
# - Clean up log files if > 5mb
#
# Simply add the target hosts in the "hosts" file, like:
# my-server-01.herokuapp.com
# my-server-02.herokuapp.com
# NOTICE: There must be a new line at the end of the "hosts" file.
@backslash-f
backslash-f / Swift.playground
Created January 23, 2022 19:54
Charles + Swift Playgrounds
// "Charles Enabler"
// https://stackoverflow.com/a/57253011/584548
public class NetworkEnabler: NSObject, URLSessionDelegate {
public func urlSession(_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}
@backslash-f
backslash-f / ddns-start
Created December 10, 2021 20:40
Merlin + DuckDNS with Double NAT
#!/bin/sh
# register a subdomain at https://www.duckdns.org/ to get your token
# put 'hostname|token' in the 'Host Name' field under DDNS (custom)
# e.g. myhost|abcdefgh-1234-5678-9876-f71b0ed7a7fe
DDNS_HOSTNAME_FIELD=$(nvram get ddns_hostname_x)
SUBDOMAIN=$(echo "$DDNS_HOSTNAME_FIELD" | awk -F'|' '{print $1}')
TOKEN=$(echo "$DDNS_HOSTNAME_FIELD" | awk -F'|' '{print $2}')
IP="$(curl -fs4 https://myip.dnsomatic.com/)"