Skip to content

Instantly share code, notes, and snippets.

Avatar

Kashif Jilani kashiftriffort

View GitHub Profile
@kashiftriffort
kashiftriffort / URLSessionInterception.swift
Last active Dec 15, 2020
URLSession swizzling in Swift
View URLSessionInterception.swift
extension URLSessionConfiguration {
@objc
static func setupSwizzledSessionConfiguration() {
guard self == URLSessionConfiguration.self else {
return
}
let defaultSessionConfiguration = class_getClassMethod(URLSessionConfiguration.self, #selector(getter: URLSessionConfiguration.default))
@kashiftriffort
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)
print("\(hour):\(minute):\(second)")
@kashiftriffort
kashiftriffort / goodreads-scraper.py
Created Jul 26, 2020
Python BeautifulSoup Scraper that scrapes book covers, titles, descriptions, average rating, rating and authors from www.goodreads.com
View goodreads-scraper.py
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
import re
url= "https://www.goodreads.com/shelf/show/thriller"
page = requests.get(url)
soup = bs(page.content, 'html.parser')
print(soup)
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) {
print(result)
}
}
func findItem<T: Equatable>(of foundItem: T, in items: [T]) -> Int? {
@kashiftriffort
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 {
return
}
let sendActionSelector = #selector(self.sendAction(_:to:from:for:))
let swizzleActionSelector = #selector(self.interceptAction(_:to:from:for:))
let sendActionMethod = class_getInstanceMethod(self, sendActionSelector)
@kashiftriffort
kashiftriffort / NSURLConnectionInterceptor.swift
Last active Apr 20, 2020
NSURLConnection Swizzling in Swift
View NSURLConnectionInterceptor.swift
extension NSURLConnection {
@objc
static func setupURLConnectionConfiguration() {
guard self == NSURLConnection.self else {
return
}
let originalRequestSelector = #selector(self.init(request:delegate:startImmediately:))
@kashiftriffort
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 {