Skip to content

Instantly share code, notes, and snippets.


Kashif Jilani kashiftriffort

View GitHub Profile
kashiftriffort / CombineSample.swift
Last active Apr 20, 2020
Combine Example in Swift
View CombineSample.swift
enum HTTPError: LocalizedError {
case statusCode
enum RequestError: Error {
case sessionError(error: Error)
struct Post: Codable {
kashiftriffort / URLSessionInterception.swift
Last active Dec 15, 2020
URLSession swizzling in Swift
View URLSessionInterception.swift
extension URLSessionConfiguration {
static func setupSwizzledSessionConfiguration() {
guard self == URLSessionConfiguration.self else {
let defaultSessionConfiguration = class_getClassMethod(URLSessionConfiguration.self, #selector(getter: URLSessionConfiguration.default))
kashiftriffort / NSURLConnectionInterceptor.swift
Last active Apr 20, 2020
NSURLConnection Swizzling in Swift
View NSURLConnectionInterceptor.swift
extension NSURLConnection {
static func setupURLConnectionConfiguration() {
guard self == NSURLConnection.self else {
let originalRequestSelector = #selector(self.init(request:delegate:startImmediately:))
kashiftriffort / InterceptAction.swift
Last active Apr 21, 2020
Intercept Action Swizzling in Swift
View InterceptAction.swift
@objc static func swizzleMethod() {
guard self == UIApplication.self else {
let sendActionSelector = #selector(self.sendAction(_:to:from:for:))
let swizzleActionSelector = #selector(self.interceptAction(_:to:from:for:))
let sendActionMethod = class_getInstanceMethod(self, sendActionSelector)
View ExampleGeneric.swift
// Find index position of item using Generic
func genericFindItem() {
let names = ["A", "B", "C", "D", "E"]
if let result = self.findItem(of: "D", in: names) {
func findItem<T: Equatable>(of foundItem: T, in items: [T]) -> Int? {
kashiftriffort /
Created Jul 26, 2020
Python BeautifulSoup Scraper that scrapes book covers, titles, descriptions, average rating, rating and authors from
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
import re
url= ""
page = requests.get(url)
soup = bs(page.content, 'html.parser')
kashiftriffort / DateComponent.swift
Last active Aug 7, 2020
Compare Date and find hour, minutes and seconds.
View DateComponent.swift
//First find a new instance of Date, and get current Calendar details. Now as per our needs we need to find components. In most case we use hour, minute and second. However there are full list of Calendar components like era, year, month, day, hour, minute, second, weekday, weekdayOrdinal, quarter, weekOfMonth, weekOfYear, yearForWeekOfYear, nanosecond, calendar and timeZone
//To get values of hour, minute and second we need to add following code.
let date = Date()
let calendar = Calendar.current
let hour = calendar.component(.hour, from: date)
let minute = calendar.component(.minute, from: date)
let second = calendar.component(.second, from: date)