Skip to content

Instantly share code, notes, and snippets.


Keybase proof

I hereby claim:

  • I am hashaam on github.
  • I am hashaam ( on keybase.
  • I have a public key whose fingerprint is 9B13 E340 5453 901A CB45 8408 2B0C BF4B F563 75A7

To claim this, I am signing this object:

hashaam / strip-html-tags-in-swift.swift
Last active May 13, 2022 06:18
Strip HTML tags in Swift
View strip-html-tags-in-swift.swift
let htmlString = "LCD Soundsystem was the musical project of producer <a href='' class='bbcode_artist'>James Murphy</a>, co-founder of <a href='' class='bbcode_tag' rel='tag'>dance-punk</a> label <a href='' class='bbcode_label'>DFA</a> Records. Formed in 2001 in New York City, New York, United States, the music of LCD Soundsystem can also be described as a mix of <a href='' class='bbcode_tag' rel='tag'>alternative dance</a> and <a href='' class='bbcode_tag' rel='tag'>post punk</a>, along with elements of <a href='' class='bbcode_tag' rel='tag'>disco</a> and other styles. <br />"
let htmlStringData = String.Encoding.utf8)!
let options: [String: Any] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
hashaam / configure-audio-session-for-background-audio-mode.swift
Last active June 14, 2017 20:52
Configure Audio Session for background audio mode (iOS Project)
View configure-audio-session-for-background-audio-mode.swift
import UIKit
import AVFoundation
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
hashaam / display-now-playing-information-in-command-center.swift
Created June 14, 2017 21:11
Display now playing information in Command Center
View display-now-playing-information-in-command-center.swift
import UIKit
import MediaPlayer
class ViewController: UIViewController {
override func viewDidLoad() {
hashaam / handle-remote-control-commands.swift
Last active August 31, 2017 11:28
Handle Remote Control Commands
View handle-remote-control-commands.swift
import UIKit
import MediaPlayer
class ViewController: UIViewController {
var player: AVPlayer?
func setupRemoteCommandCenter(enable: Bool) {
hashaam / custom-sorting-an-array-in-swift.swift
Last active August 31, 2017 11:27
Custom Sorting an Array in Swift
View custom-sorting-an-array-in-swift.swift
struct Business {
let businessId: Int
let rating: Int
func sortBusinesses(_ businesses: [Business]) -> [Business] {
let set = NSOrderedSet(array: businesses)
hashaam / get-device-token-for-remote-push-notifications-in-swift.swift
Last active October 30, 2021 13:55
Get device token for remote push notifications in Swift
View get-device-token-for-remote-push-notifications-in-swift.swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = { data -> String in
return String(format: "%02.2hhx", data)
let token = tokenParts.joined()
hashaam / uiwindow-presentation-context.swift
Last active August 31, 2017 11:26
UIWindow Presentation Context - Get top most presented UIViewController of UIWindow
View uiwindow-presentation-context.swift
extension UIWindow {
func presentationContext(context: UIViewController? = nil) -> UIViewController? {
var presentationContextViewController = rootViewController
if let context = context {
presentationContextViewController = context
hashaam / using-uiwindow-presentation-context.swift
Last active August 31, 2017 11:24
Using UIWindow Presentation Context
View using-uiwindow-presentation-context.swift
if let delegate = UIApplication.shared.delegate, let window = delegate.window, let viewController = window?.presentationContext() {
// perform action on viewController
hashaam / get-filename-without-extension.swift
Last active March 22, 2019 10:11
Get filename without extension
View get-filename-without-extension.swift
let path = "hls_a128_v4.m3u8"
let url = URL(string: path)
let filename = url?.deletingPathExtension().lastPathComponent
print(filename) // hls_a128_v4
let fileExtension = url?.pathExtension