Skip to content

Instantly share code, notes, and snippets.

@LeonardoCardoso
LeonardoCardoso / UIViewControllerExtension.swift
Created January 22, 2017 00:54
Topmost View Controller
import UIKit
extension UIViewController {
static var topmostViewController: UIViewController? { return UIApplication.shared.keyWindow?.topmostViewController }
var topmostViewController: UIViewController? { return presentedViewController?.topmostViewController ?? self }
}
@LeonardoCardoso
LeonardoCardoso / combinations.py
Created November 29, 2016 12:30
Generate all combinations of a string, uppercase and lowercase.
def recurse (pref,suff):
# If no characters left, just print prefix.
if suff == "":
print pref
return
# Otherwise add lowercase of first suffix letter to prefix
# and recur with that and the remainder of the suffix.
# Then do the same for uppercase.
@LeonardoCardoso
LeonardoCardoso / change-screen-shot-location.sh
Created August 31, 2016 13:53
Change Screen Shot location on Mac
defaults write com.apple.screencapture location ~/PATH_YOU_WANT; killall SystemUIServer
@LeonardoCardoso
LeonardoCardoso / better-touch-tool.plist
Last active October 30, 2018 09:57
Script to keep BetterTouchTool running.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN” "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
@LeonardoCardoso
LeonardoCardoso / xcode-build-and-test.sh
Last active October 3, 2019 16:59
XCode Build and Test
xcodebuild -project YourProject.xcodeproj -scheme YourProjectScheme -destination "OS=10.0,name=iPhone 7" -sdk "iphonesimulator10.0" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty -c;
xcodebuild -project YourProject.xcodeproj -scheme YourProjectSchemeWatchOS -destination "OS=3.0,name=Apple Watch Series 2 - 42mm" -sdk "watchsimulator3.0" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty -c;
xcodebuild -project YourProject.xcodeproj -scheme YourProjectSchemeTvOS -destination "OS=10.0,name=Apple TV 1080p" -sdk "appletvsimulator10.0" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty -c;
xcodebuild -project YourProject.xcodeproj -scheme YourProjectSchemeMacOS -destination "arch=x86_64" -sdk "macosx10.12" RUN_TESTS="YES" BUILD_EXAMPLE="NO"
@danieleggert
danieleggert / GPG and git on macOS.md
Last active March 6, 2025 20:45
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@LeonardoCardoso
LeonardoCardoso / add-space-on-dock.sh
Created June 22, 2016 11:41
Add space on Mac's Dock
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'
killall Dock
@joeblau
joeblau / AppleCodeLogo.md
Created June 15, 2016 17:25
Apple Code Logo
                                    _.
                                _/=\:<
                              .#/*let}
                            //as\@#:~/
                           try()]:=./
                          *~let:>@{#
                          </>)#@~*/
                         (+~:~/+/
                         /={+"
extension String {
var isCPF: Bool {
let cpf = self.stringByReplacingOccurrencesOfString(".", withString: "").stringByReplacingOccurrencesOfString("-", withString: "")
if cpf.characters.count == 11 {
let d1 = Int(cpf.substringWithRange(Range(cpf.startIndex.advancedBy(9) ..< cpf.startIndex.advancedBy(10))))
let d2 = Int(cpf.substringWithRange(Range(cpf.startIndex.advancedBy(10) ..< cpf.startIndex.advancedBy(11))))
@LeonardoCardoso
LeonardoCardoso / Serializer.swift
Created May 31, 2016 13:05
JSON Serializer and Converter for URL and String
// JSON Serializer helper class
class Serializer {
// Retrieve JSON from Url and tries to parse it
static func jsonFromUrl(url: String, completionHandler: (NSDictionary) -> (), errorHandler: (NSError?) -> ()) {
let url = NSURL(string: url)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in