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
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
}
@volkanbicer
volkanbicer / singleNumber.swift
Created November 10, 2017 05:13
Single number in array
func singleNumber(_ nums: [Int]) -> Int {
var result:Int = 0
for value in nums{
result ^= value
}
return result
}
@volkanbicer
volkanbicer / moveZeros.swift
Created November 10, 2017 05:16
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
func moveZeroes(_ nums: inout [Int]) {
var numZerosSeen = 0
for (index, val) in nums.enumerated(){
if val == 0{
nums.remove(at: index-numZerosSeen)
nums.append(0)
numZerosSeen += 1
}
}
}
@volkanbicer
volkanbicer / twoSum.swift
Created November 10, 2017 07:19
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
func twoSum(_ array:[Int], _ sum: Int) -> (Int,Int)?{
var dic = [Int: Int]()
for i in 0..<array.count{
let complement = sum - array[i]
if dic[complement] != nil{
return (i, dic[complement]!)
}
dic[array[i]] = i
}
return nil
@volkanbicer
volkanbicer / queue.swift
Created November 10, 2017 07:46
Queue data type for swift
public struct Queue<T>{
private var array = [T]()
public mutating func enqueue(_ item: T){
array.append(item)
}
public mutating func dequeue() -> T?{
if isEmpty{
return nil