Skip to content

Instantly share code, notes, and snippets.

View volkanbicer's full-sized avatar
🔥

Volkan Bicer volkanbicer

🔥
View GitHub Profile
function loadPage(times = 10, interval = 300, callback){
var counter = 0
var interval = setInterval(()=> {
counter++;
window.scrollTo(0,document.body.scrollHeight);
if(callback){
callback();
}
if(counter === times){
clearInterval(interval);
@volkanbicer
volkanbicer / Push.swift
Created October 5, 2017 20:26 — forked from benaneesh/Push.swift
Push notification in swift (iOS)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// notification
if let options = launchOptions {
let notificationPayload: NSDictionary = options[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary
// do somehting with the notifications
}
// Register for Push Notitications, if running iOS 8
@volkanbicer
volkanbicer / BinarySearch.swift
Last active November 11, 2017 15:01
Binary search function for swift
import Foundation
let numbers = Array(1...1000)
func binarySearch<T: Comparable>(_ a: [T], key: T, range:Range<Int>) -> Int?{
if range.lowerBound >= range.upperBound{ return nil}
let midIndex = range.lowerBound + (range.upperBound - range.lowerBound)/2
if key < a[midIndex]{
@volkanbicer
volkanbicer / insertionSort.swift
Last active November 11, 2017 16:32
Implementation of insertion sort in Swift
// swap
func insertionSort(_ a:[Int]) -> [Int]{
var array = a
for i in 1..<array.count{
var k = i
while k>0 && array[k-1] > array[k]{
(array[k-1], array[k]) = (array[k], array[k-1])
k -= 1
}
}
@volkanbicer
volkanbicer / selectionSort.swift
Last active November 11, 2017 16:39
Selection sort for swift
func selectionSort(_ array: [Int]) -> [Int]{
var a = array
for i in 0..<a.count - 1{
var lowest = i
for j in i+1..<a.count{
if a[j] < a[lowest]{
lowest = j
}
}
if lowest != i{
@volkanbicer
volkanbicer / bubbleSort.swift
Last active November 11, 2017 16:49
Bubble sort for swift
import Foundation
func bubbleSort(_ list: [Int]) -> [Int]{
var array = list
var swapped = true
while swapped{
swapped = false
for i in 0..<array.count-1{
if array[i] > array[i+1]{
(array[i], array[i+1]) = (array[i+1], array[i])
public class BinarySearchTree<T:Comparable>{
private(set) public var value: T
private(set) public var parent: BinarySearchTree<T>?
private(set) public var leftChield: BinarySearchTree<T>?
private(set) public var rightChield: BinarySearchTree<T>?
public init(value: T){
self.value = value
}
import Foundation
func palindrom(_ string: String) -> Bool{
let strippedString = string.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil)
let length = strippedString.characters.count
if length == 0 {
return true
}else if length > 1{
return isPalindrom(strippedString.lowercased(), left: 0, right: length-1)
@volkanbicer
volkanbicer / kthSmallest.swift
Created November 10, 2017 04:43
Kth Smallest Element in a BST
func kthSmallest(_ root: TreeNode?, _ k: Int) -> Int {
guard let _ = root else {
return -1
}
var count = 0
var stack = [TreeNode]()
var root = root
while !stack.isEmpty || root != nil {
@volkanbicer
volkanbicer / reversedString.swift
Created November 10, 2017 05:10
Function that takes a string as input and returns the string reversed.
func reverseString(_ s: String) -> String {
var reversed = ""
var stringArray = Array(s.characters)
var n = s.characters.count
for i in 0..<stringArray.count{
reversed.append(stringArray[n-1-i])
}
return reversed
}