Skip to content

Instantly share code, notes, and snippets.

View gazolla's full-sized avatar

Sebastiao Gazolla Jr gazolla

View GitHub Profile
import Foundation
/*
1108. Defanging an IP Address
Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
Example 1:
@gazolla
gazolla / createContact.swift
Last active July 19, 2018 19:49
How to create a Contact programmatically using swift 3 for iOS
import Contacts
func createContact()->CNMutableContact{
let contact = CNMutableContact()
contact.namePrefix = "John"
contact.nameSuffix = "Applesee"
contact.organizationName = "Apple"
contact.jobTitle = "Software Engineer"
@gazolla
gazolla / QuickSort.swift
Created June 17, 2017 13:42
QuickSort created by gazolla - https://repl.it/IkKD/0
func quickSort<T:Comparable>(_ list:[T])->[T]{
if list.count == 0 {
return []
}
let pivot = list[list.count/2]
let equal = list.filter{ $0 == pivot }
let less = list.filter{ $0 < pivot }
let greater = list.filter{ $0 > pivot }
return quickSort(less) + equal + quickSort(greater)
}
@gazolla
gazolla / textField.swift
Created June 20, 2016 01:05
Programmatically create UITextField
let sampleTextField = UITextField(frame: CGRectMake(20, 100, 300, 40))
sampleTextField.placeholder = "Enter text here"
sampleTextField.font = UIFont.systemFontOfSize(15)
sampleTextField.borderStyle = UITextBorderStyle.RoundedRect
sampleTextField.autocorrectionType = UITextAutocorrectionType.No
sampleTextField.keyboardType = UIKeyboardType.Default
sampleTextField.returnKeyType = UIReturnKeyType.Done
sampleTextField.clearButtonMode = UITextFieldViewMode.WhileEditing;
sampleTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.Center
sampleTextField.delegate = self
@gazolla
gazolla / stack.swift
Created June 20, 2016 01:00
Programmatically create UIStackView
lazy var v1:UIView = {
let v = UIView()
v.backgroundColor = .blueColor()
return v
}()
lazy var v2:UIView = {
let v = UIView()
v.backgroundColor = .blueColor()
return v
@gazolla
gazolla / reverse.swift
Last active May 24, 2016 03:37
Reverse all Strings from a sentence
let sentence = "Hello, My name is Bob"
let result = sentence.characters.reversed().map { String($0) }.joined(separator:"")
print(result)
func quicksort<T:Comparable>(list:[T])->[T]{
if list.isEmpty {
return list
}
let pivot = list[list.count/2]
let equal = list.filter{ $0 == pivot }
let less = list.filter{ $0 < pivot }
let greater = list.filter{ $0 > pivot }
return quicksort(less) + equal + quicksort(greater)
}
@gazolla
gazolla / HTTP.swift
Last active September 20, 2016 15:51
HTTP encapsulation
//
// HTTP.swift
// TableTest2
//
// Created by Gazolla on 22/05/16.
// Copyright © 2016 Gazolla. All rights reserved.
//
import Foundation
import UIKit
@gazolla
gazolla / gist:00278db86636a35ac958
Created April 11, 2015 18:48
Convert serial.read() into a useable string using Arduino
char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void setup() {
Serial.begin(9600);
Serial.write("Power On");
}
char Comp(char* This) {
@gazolla
gazolla / StreamReader.swift
Last active May 20, 2016 15:07
The following Swift code was created by Martin R. (http://stackoverflow.com/users/1187415/martin-r) and it should be used to read files line-by-line as explained in http://stackoverflow.com/questions/24581517/read-a-file-url-line-by-line-in-swift
class StreamReader {
let encoding : UInt
let chunkSize : Int
var fileHandle : NSFileHandle!
let buffer : NSMutableData!
let delimData : NSData!
var atEof : Bool = false