Instantly share code, notes, and snippets.

View TimeStampToDate.swift
func formatterDate(stringDate: String) -> Date? {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSxxxxx"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
guard let newDate = formatter.date(from: stringDate) else { return nil }
return newDate
}
let stringDate = formatterDate(stringDate: "2018-08-30T15:26:27.357902-03:00")
print(stringDate)
View StringDynamicParameterVariable.swift
var str = "Hello %@, welcome to playground"
let tvar = String(format: NSLocalizedString(str, comment: "%@"), "Mike")
print(tvar)
View SorteioDeNomes
var convidados: [String] = []
convidados.append("Michel")
convidados.append("Karen")
convidados.append("Simba")
convidados.append("Oliver")
convidados.append("Thales")
convidados.append("Ricardo")
var randomNum = arc4random_uniform(UInt32(convidados.count))
print("Sorteio CocoaHeads POA Agosto 2018 \n\n")
var str = "O(A) Vencedor(a) é >> \(convidados[Int(randomNum)]) <<"
View UIControl+ListenBlock.swift
import Foundation
import UIKit
extension UIControl {
func listen(_ action: @escaping () -> (), for controlEvents: UIControlEvents) -> AnyObject {
let sleeve = ClosureSleeve(attachTo: self, closure: action, controlEvents: controlEvents)
addTarget(sleeve, action: #selector(ClosureSleeve.invoke), for: controlEvents)
return sleeve
}
View Rename.go
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"unicode"
"golang.org/x/text/transform"
View gist:db0116041c48d3d0d3643c7f046fa061

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
View install-multiple-jdk-on-macos-high-sierra.md

Install Multiple Java Versions on macOS High Sierra

Install Homebrew Cask

On Mac, Homebrew is the de-facto package manager, and Homebrew Cask is the app manager. I’m going to use Cask to install Java 7 and 9.

Install Homebrew Cask first if you haven’t:

brew update
brew tap caskroom/cask
View macosx-install-php-oracle-oci8-pdo_oci.md

Installation

This procedure is tested on Mac OS X 10.10.5 with Developpers tools installed (xCode).

PHP 5.6 installed with Homebrew.

Preparation

Download the following files from Oracle website (yes, you need to create an account and accept terms):

View SimplePickerView.swift
import UIKit
class SimplePickerView : UIPickerView {
class SimplePickerViewModel : NSObject, UIPickerViewDelegate, UIPickerViewDataSource {
var titles: [String]
var selectionHandler: ((_ pickerView: UIPickerView, _ row: Int, _ title: String) -> ())?
init(titles: [String], selectionHandler: ((_ pickerView: UIPickerView, _ row: Int, _ title: String) -> ())? = nil) {
View Picker.swift
class PickerSource : NSObject, UIPickerViewDelegate, UIPickerViewDataSource {
var data: [[String]] = []
var selectionUpdated: ((component: Int, row: Int) -> Void)?
// MARK: UIPickerViewDataSource
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return data.count
}