Skip to content

Instantly share code, notes, and snippets.

View kashiftriffort's full-sized avatar

Kashif Jilani kashiftriffort

View GitHub Profile
@kashiftriffort
kashiftriffort / DateComponent.swift
Last active August 7, 2020 06:41
Compare Date and find hour, minutes and seconds.
//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 July 26, 2020 07:13
Python BeautifulSoup Scraper that scrapes book covers, titles, descriptions, average rating, rating and authors from www.goodreads.com
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)
@kashiftriffort
kashiftriffort / ExampleGeneric.swift
Last active May 6, 2020 05:44
Generic in 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 April 21, 2020 08:33
Intercept Action Swizzling in 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 April 20, 2020 13:11
NSURLConnection Swizzling in Swift
extension NSURLConnection {
@objc
static func setupURLConnectionConfiguration() {
guard self == NSURLConnection.self else {
return
}
let originalRequestSelector = #selector(self.init(request:delegate:startImmediately:))
@kashiftriffort
kashiftriffort / URLSessionInterception.swift
Last active September 28, 2023 23:35
URLSession swizzling in 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 / CombineSample.swift
Last active April 20, 2020 12:50
Combine Example in Swift
enum HTTPError: LocalizedError {
case statusCode
}
enum RequestError: Error {
case sessionError(error: Error)
}
struct Post: Codable {