Skip to content

Instantly share code, notes, and snippets.

View gazolla's full-sized avatar

Sebastiao Gazolla Jr gazolla

View GitHub Profile
@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 / 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 / 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 / createContact.swift
Last active May 16, 2024 18:37
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"
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 / App.java
Created July 23, 2024 23:25
Bubble sort algorithm in Java
public class App {
public static void main(String[] args) {
int[] array = {5,9,1,8,2,7,3,6,4};
System.out.println("original " + array);
bubbleSort(array);
System.out.println("sorted " + array);
}
private static void bubbleSort(int[] array) {
boolean swapped;
int n = array.length;