Skip to content

Instantly share code, notes, and snippets.

View dbonates's full-sized avatar
🏠
Working from home

Daniel Bonates dbonates

🏠
Working from home
  • Self Industry
  • Florianopolis, Brazil
View GitHub Profile
@dbonates
dbonates / app-preview-from-simulator.sh
Created February 11, 2018 14:57
command to record app preview on current booted simulator
xcrun simctl io booted recordVideo /path/Video.mov
@dbonates
dbonates / string_valid_email.swift
Created February 5, 2018 22:58
// MARK: - String Extension to validade email
extension String {
func isValidEmail() -> Bool {
let emailRegex = "(?:[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[\\p{L}0-9!#$%\\&'*+/=?\\^_`{|}" +
"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" +
"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\p{L}0-9](?:[a-" +
"z0-9-]*[\\p{L}0-9])?\\.)+[\\p{L}0-9](?:[\\p{L}0-9-]*[\\p{L}0-9])?|\\[(?:(?:25[0-5" +
"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" +
"9][0-9]?|[\\p{L}0-9-]*[\\p{L}0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" +
"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
@dbonates
dbonates / codable_userdefaults.swift
Created January 28, 2018 16:18
Swift 4 snipet for persist a Struct that conform to Codable protocol
struct Station: Codable {
let id: Int
let name: String
let logoURL: URL
let thumbnailURL: URL
let cityName: String
let stateName: String
var streamingURL: URL? = nil
}
@dbonates
dbonates / string_search_terms_utils.swift
Last active February 16, 2018 12:06
some String methods to help on searching text from textFields
public extension String {
// compares two strings and returns if they should be considered the same as the given string
func meansTheSame(of word: String) -> Bool {
return self.folding(options: .diacriticInsensitive, locale: nil).lowercased() == word.folding(options: .diacriticInsensitive, locale: nil).lowercased()
}
// check if string contains all terms from a given string
func containTerms(from aString: String) -> Bool {
let terms = aString.split(separator: " ").map(String.init)
@dbonates
dbonates / ios_framework_flat.sh
Created November 22, 2017 22:25
Build Flat Framework - for device and simulator
#!/bin/sh
# add and it as a Run Script Phase on Buidl Phases on Xcode!
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

Keybase proof

I hereby claim:

  • I am dbonates on github.
  • I am dbonates (https://keybase.io/dbonates) on keybase.
  • I have a public key ASCYYJZRDcLiK9_oS9HF05YlNhnuviNiefeB6tGkub1F8Qo

To claim this, I am signing this object:

/Applications/Install\ macOS\ High\ Sierra\ Beta.app/Contents/Resources/createinstallmedia --volume /Volumes/HSIERRA --applicationpath /Applications/Install\ macOS\ High\ Sierra\ Beta.app
@dbonates
dbonates / remove_mongodb.sh
Last active September 7, 2017 00:25
steps to remove mongodb on macOS
# See if mongo is in the launch/startup list
launchctl list | grep mongo
# Remove mongodb from the launch/startup
launchctl remove homebrew.mxcl.mongodb
# Kill the mongod process just in case it's running
pkill -f mongod
# Now you can safely remove mongodb using Homebrew
@dbonates
dbonates / lead_and_tail_string.swift
Last active May 23, 2017 15:49
Extension to extract handy substrings from a String. Ex.: credit card number masks. Returns empty string if you abuse it :P
import Foundation
extension String {
public func tailString(from offset: Int) -> String {
return offset > -1 ? "" : self.substring(
from: self.index(self.endIndex,
offsetBy: abs(offset) > characters.count ? -characters.count : offset)
)
}
@dbonates
dbonates / dos_bar.swift
Created May 23, 2017 00:19
A snippet for a dos bar style in Swift
import Foundation
let voidChar = "░"
let fillChar = "█"
let max = 20
for i in 0..<max {
let perc = (Float(i)/Float(max))*100