Skip to content

Instantly share code, notes, and snippets.

View antonyalkmim's full-sized avatar

Antony Alkmim antonyalkmim

View GitHub Profile
@antonyalkmim
antonyalkmim / CPFnCNPJUtils.js
Created May 29, 2018 14:22
Script javascript para verificar se CPF e CNPJ são válidos.
const calcularDigito = (str, peso) => {
var soma = 0;
var indice = str.length - 1;
var digito;
while (indice >= 0) {
digito = parseInt(str.substring(indice, indice + 1));
soma += digito * peso[peso.length - str.length + indice];
indice--
infix operator ?!: NilCoalescingPrecedence
@_transparent
public func ?!<T: OptionalType>(value: T, error: @autoclosure () -> Error) throws -> T.ValueType {
if let value = value.optionalValue { return value }
throw error()
}
@antonyalkmim
antonyalkmim / UIViewController+UITextfield.swift
Last active October 17, 2018 08:48
iOS UIViewController extension to fix keyboard overriding textfield
//
// UIViewController+ext.swift
// Antony Alkmim
//
// Created by Antony Alkmim on 03/07/18.
// Copyright © 2018 Antony Alkmim. All rights reserved.
//
import UIKit
@antonyalkmim
antonyalkmim / SwipeableCell.swift
Created July 12, 2018 19:18
Swipeable UITableViewCell where you can use custom view behind cell.contentView
//
// SwipeableCell.swift
// Antony Alkmim
//
// Created by Antony Alkmim on 09/07/18.
// Inspired by: https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views
//
import UIKit
import PINRemoteImage
@antonyalkmim
antonyalkmim / gist:462abefc914a0db40ca1f384755819c3
Created November 12, 2019 12:11 — forked from steipete/ios-xcode-device-support.sh
Using iOS 13.2 devices with Xcode 11.1 (instead of Xcode 11.2) (also, Xcode 10.3)
// The trick is to link the DeviceSupport folder from the beta to the stable version.
// sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
// Support iOS 13.2 devices (Xcode 11.2) with Xcode 11.1:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.2 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Xcode 10.3 to Xcode 11
sudo ln -s /Applications/Xcode-11.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.0 /Applications/Xcode-10.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
@antonyalkmim
antonyalkmim / cleanup.sh
Created October 9, 2020 12:21 — forked from Bunn/cleanup.sh
Cleanup space
#!/bin/bash
echo "Removing unavailable simulators..."
xcrun simctl delete unavailable
echo "Brew cleanup..."
brew cleanup
echo "Removing Xcode Caches..."
rm -rf ~/Library/Caches/com.apple.dt.Xcode
@antonyalkmim
antonyalkmim / if+when.swift
Last active October 26, 2022 19:59
Iff + When Swift implementation
typealias IfResultClosure<Result> = (() -> Result)
typealias Case<Value, Result> = (Value, IfResultClosure<Result>)
@_functionBuilder
struct CaseBuilder<Value, Result> {
static func buildBlock(_ cases: Case<Value, Result>...) -> [Case<Value, Result>] {
cases
}
}
@antonyalkmim
antonyalkmim / CurrencyTextField.swift
Created December 13, 2020 18:39
SwiftUI CurrencyTextField
import SwiftUI
struct CurrencyTextField: View {
let title: String
@Binding var amountString: String
var body: some View {
TextField(title, text: $amountString)
.keyboardType(.numberPad)
@antonyalkmim
antonyalkmim / oh-my-zsh-setup.md
Last active April 4, 2021 18:28
Setup Cmd+[left|right] and Option+[left|right] mac shortcuts for iTerm2
@antonyalkmim
antonyalkmim / swiftui+uiview.swift
Created September 10, 2021 13:04
SwiftUI+UIView.swift
import UIKit
import SwiftUI
extension UIViewController {
/// Add a SwiftUI `View` as a child of the input `UIView`.
/// - Parameters:
/// - swiftUIView: The SwiftUI `View` to add as a child.
/// - view: The `UIView` instance to which the view should be added.
func addSubview<Content>(_ swiftUIView: Content, to view: UIView) where Content: View {