Skip to content

Instantly share code, notes, and snippets.

View rafattouqir's full-sized avatar

MD Rafat Touqir rafattouqir

View GitHub Profile
@rafattouqir
rafattouqir / ThrottledSearchController.swift
Created February 2, 2020 12:19
Simple RxSwift like Throttle functionality added to UISearchBar and UISearchController
// ThrottledSearchController.swift
// Created by Daniele Margutti on 10/19/2017
// Updated by RAFAT TOUQIR RAFSUN.
import UIKit
class ThrottledSearchController: UISearchController{
// Mark this property as lazy to defer initialization until
// the searchBar property is called.
private lazy var customSearchBar = ThrottledSearchBar()
protocol LoaderViewType: UIView {
func startAnimating()
func stopAnimating()
}
class LoaderButton: UIButton, LoaderViewType {
fileprivate let activityLoader: UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView(style: .gray)
indicator.translatesAutoresizingMaskIntoConstraints = false
import UIKit
// MARK: - SafeArea Extensions
extension UIView {
var safeTopAnchor: NSLayoutYAxisAnchor {
if #available(iOS 11.0, *) {
return self.safeAreaLayoutGuide.topAnchor
}
return self.topAnchor
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: CustomCollectionViewCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
...
//add shadow
cell.applyShadow()
....
return cell
}
@rafattouqir
rafattouqir / tab.bash
Created July 21, 2019 17:00 — forked from bobthecow/tab.bash
Open new Terminal tabs from the command line
#!/bin/bash
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#
//call the method
let convertedDateString = self.dateFromString("2019-05-20", fromFormat: "yyyy-MM-dd", toFormat: "dd-MM-yyyy")
print(convertedDateString ?? "Failed to convert date")
func dateFromString(_ dateString:String, fromFormat:String, toFormat: String) -> String? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = fromFormat
@rafattouqir
rafattouqir / .bash_profile
Created May 16, 2019 18:03
My .bash_profile and .bashrc
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
@rafattouqir
rafattouqir / LoaderWithCancelView+PKHUBCustomView.swift
Created May 16, 2019 07:35
PKHUD custom loader with cancel button and action on cancel button click
class LoaderWithCancelView: UIView,PKHUDAnimating{
let progressView: PKHUDProgressView = {
let pkHUDPV = PKHUDProgressView()
pkHUDPV.translatesAutoresizingMaskIntoConstraints = false
return pkHUDPV
}()
let buttonCancel:UIButton = {
let button = UIButton()
button.setTitle("Cancel", for: .normal)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView === self.topCollectionView{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "topCollectionViewCell", for: indexPath) as! TopCollectionViewCell
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "bottomCollectionViewCell", for: indexPath) as! BottomCollectionViewCell
return cell
}
@rafattouqir
rafattouqir / SafeAreaTopAnchorSnippet.swift
Last active March 5, 2019 03:28
iOS 11 safe area layout guide backwards compatibility upto iOS 9
let safeAreaTopAnchor:NSLayoutYAxisAnchor?
if #available(iOS 11.0, *) {
safeAreaTopAnchor = contentView.safeAreaLayoutGuide.topAnchor
} else {
// Fallback on earlier versions
var parentViewController: UIViewController? {
var parentResponder: UIResponder? = self
while parentResponder != nil {
parentResponder = parentResponder!.next