This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSURLConnection { | |
@objc | |
static func setupURLConnectionConfiguration() { | |
guard self == NSURLConnection.self else { | |
return | |
} | |
let originalRequestSelector = #selector(self.init(request:delegate:startImmediately:)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLSessionConfiguration { | |
@objc | |
static func setupSwizzledSessionConfiguration() { | |
guard self == URLSessionConfiguration.self else { | |
return | |
} | |
let defaultSessionConfiguration = class_getClassMethod(URLSessionConfiguration.self, #selector(getter: URLSessionConfiguration.default)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum HTTPError: LocalizedError { | |
case statusCode | |
} | |
enum RequestError: Error { | |
case sessionError(error: Error) | |
} | |
struct Post: Codable { |