Skip to content

Instantly share code, notes, and snippets.

View gazolla's full-sized avatar

Sebastiao Gazolla Jr gazolla

View GitHub Profile
@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;
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 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"
@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) {