Skip to content

Instantly share code, notes, and snippets.

View prasadpamidi's full-sized avatar
👨‍💻

Prasad Pamidi prasadpamidi

👨‍💻
  • San Francisco, CA
View GitHub Profile
@prasadpamidi
prasadpamidi / SegmentedCollectionViewController.swift
Last active October 30, 2022 11:30
Issue with large navigation bar and collection view
import UIKit
class SegmentedControlSupplementaryView: UICollectionReusableView {
let segmentControl = UISegmentedControl(items: ["Item 1", "Items 2", "Items 3"])
static let reuseIdentifier = "segmented-supplementary-reuse-identifier"
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .white
@prasadpamidi
prasadpamidi / git-shorcuts
Created April 27, 2019 20:30
GIT Shortcuts
# ----------------------
# Git Aliases
# ----------------------
alias ga='git add .'
alias gau='git add --update'
alias gb='git branch'
alias gbd='git branch --delete '
alias gc='git commit'
alias gcm='git commit --message'
alias gco='git checkout'
@prasadpamidi
prasadpamidi / sieve-of-erastosthenes-in-swift.swift
Last active November 5, 2015 19:12
Sieve of Eratosthenes Algorithm implementation in Swift
//Algorithm: Sieve of Eratosthenes
//Swift 2.0 implementation for retreving all the primes until the given limit
func findPrimesUntil(limit limit: Int) -> [Int]? {
guard limit > 1 else {
return .None
}
var primes = [Bool](count: limit+1, repeatedValue: true)
for i in 0..<2 {
@prasadpamidi
prasadpamidi / Alamofire+AEXML.swift
Created August 22, 2015 12:16
An extension for Alamofire to return AEXMLDocument as response
extension Request {
public func responseAEXMLDocument(completionHandler: (NSURLRequest, NSHTTPURLResponse?, AEXMLDocument?, NSError?) -> Void) -> Self {
return response { (request: NSURLRequest, response: NSHTTPURLResponse?, responseObj: AnyObject?, responseError: NSError?) -> Void in
var parse_error: NSError?
if let obj = responseObj as? NSData, xml = AEXMLDocument(xmlData: obj, error: &parse_error) {
if let aerror = parse_error{
completionHandler(request, response, nil, aerror)
} else {
completionHandler(request, response, xml, responseError)
}
@prasadpamidi
prasadpamidi / custom_storyboard_segues.swift
Last active November 5, 2015 19:14
Snippet for using enums instead strings for Storyboard segues - Approach to prevent crashes we often face with using strings
//
// UIStoryBoard+Extensions.swift
//
// Created by Prasad Pamidi on 7/29/15.
// Copyright (c) 2015. All rights reserved.
//
import UIKit
enum SegueIdentifier:String {
@prasadpamidi
prasadpamidi / pattern_matching.swift
Last active November 5, 2015 19:15
Pattern Matching algorithm implemented in Swift
//Famous pattern matching algorithm implementation in Swift
func FindMatch(text: [Character], pattern: [Character]) -> [Int] {
let t = count(text)
let p = count(pattern)
var i = 0
var j = 0
var matchedIdxs: [Int] = []
@prasadpamidi
prasadpamidi / sorting_algorithms_in_swift.swift
Last active November 5, 2015 19:14
Swift implementation of popular sorting algorithms
import Foundation
//popular sorting algorithms in swift
//Insertion Sort
//Complexity - Best O(n) - Average O(n2)
//We will perform comparing adjacent elements in the array for array length times
func InsertionSort<T: Comparable>(var list:[T]) -> [T] {
for i in 1..<list.count {