Skip to content

Instantly share code, notes, and snippets.

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
@LeonardoCardoso
LeonardoCardoso / Reflection.swift
Created May 21, 2016 18:13
Get any class properties using reflection
// MARK: - Get properties using reflection
extension NSObject {
func properties() -> [String: String]{
var results: [String: String] = [:]
for child in Mirror(reflecting: self).children {
var propertyName = ""
@LeonardoCardoso
LeonardoCardoso / gitzip.sh
Last active October 9, 2023 22:38
Zip folder ignoring files listed on .gitignore
#...
function gitzip() {
git archive -o $@.zip HEAD
}
#... gitzip ZIPPED_FILE_NAME
class func executeAfter(delay: TimeInterval, block: @escaping () -> Void){
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay, execute: block)
}
import Foundation
extension String {
var parseJSON: AnyObject? {
let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
if let jsonData = data {
@LeonardoCardoso
LeonardoCardoso / ScrollTextView.java
Last active January 21, 2022 07:37
TextView with continuous scroll marquee animation no matter where the Activity focus is.
public class ScrollTextView extends TextView {
public ScrollTextView(Context context) {
super(context);
}
public ScrollTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@LeonardoCardoso
LeonardoCardoso / cpwd.sh
Last active October 30, 2018 09:59
One line command to copy the current terminal path on Mac
#...
alias cpwd="pwd | tr -d '\n' | pbcopy"
#...
@LeonardoCardoso
LeonardoCardoso / Podfile-Snippet
Last active October 30, 2018 09:59
Podfile Snippet: 'Build Active Architecture Only' to 'NO' and 'Valid Architectures' to '$(ARCHS_STANDARD)' to all pods
# insert this at the end of your Podfile
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |configuration|
target.build_settings(configuration.name)['ARCHS'] = '$(ARCHS_STANDARD)' # it sets 'Valid Architectures' to '$(ARCHS_STANDARD)' to all pods
target.build_settings(configuration.name)['ONLY_ACTIVE_ARCH'] = 'NO' # it sets 'Build Active Architecture Only' to 'NO'
end
end
end