Skip to content

Instantly share code, notes, and snippets.

View vdeep's full-sized avatar
🎯
Focusing

Vishal Kanojia vdeep

🎯
Focusing
  • Punjab, India
View GitHub Profile
@vdeep
vdeep / UINavigationController+Extension.swift
Created June 15, 2022 12:31
Completion block support for UINavigationController push and pop methods
import UIKit
extension UINavigationController {
func pushViewController(viewController: UIViewController, animated: Bool, completion: @escaping () -> Void) {
pushViewController(viewController, animated: animated)
if animated, let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: nil) { _ in
completion()
}
@vdeep
vdeep / virtualenv.py
Created March 12, 2021 07:42
Create virtualenv with Python 3
python -m venv ./venv
@vdeep
vdeep / README.md
Created December 6, 2019 17:43
Instructions to upload SSH keys to DigitalOcean instance manually

1

  1. Login to the console on digitalocean website.
  2. Type sudo nano /etc/ssh/sshd_config
  3. Change PasswordAuthentication from “no” to “yes” and save the file
  4. Restart sshd (Debian: sudo service sshd restart)

2

Linux, Mac (ssh-copy-id):

  1. Run `ssh-copy-id [user]@[hostname or IP address]
@vdeep
vdeep / VersionNumber.swift
Created April 16, 2019 05:27
Struct to compare version numbers
import Foundation
struct VersionNumber: Equatable, Comparable {
let components: [Int]
init(version: String?) {
components = version?.split(separator: ".").compactMap({ Int($0) }) ?? []
}
static func == (lhs: VersionNumber, rhs: VersionNumber) -> Bool {
@vdeep
vdeep / UIImage+Resize.swift
Created April 12, 2019 11:11 — forked from marcosgriselli/UIImage+Resize.swift
UIImage Resize/Scaling
//
// UIImage+Resize.swift
//
// Created by Marcos Griselli on 6/9/17.
// Copyright © 2017 Marcos Griselli. All rights reserved.
//
import Foundation
import UIKit
@vdeep
vdeep / Date.swift
Last active February 11, 2019 13:01
Get time string from a date
func timeStringFromDate(_ date: Date) -> String? {
let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
let dateTimestamp = date.timeIntervalSince1970
let currentDateTimestamp = Date().timeIntervalSince1970
let diff: TimeInterval = currentDateTimestamp - dateTimestamp
guard diff >= 0 else {
return nil
@vdeep
vdeep / CountryCode.swift
Created February 6, 2019 13:10
JSON file containing all the countries with their country codes and dial codes along with a Swift file containing the usage instructions.
import Foundation
struct CountryCode: Codable {
private class FooBar {}
enum CodingKeys: String, CodingKey {
case countryName = "name"
case countryCode = "code"
case countryDialCode = "dial_code"
}
@vdeep
vdeep / ios-cell-registration-swift.md
Last active October 28, 2022 06:36 — forked from gonzalezreal/ios-cell-registration-swift.md
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@vdeep
vdeep / UploadLambdaFunction
Created September 11, 2018 07:50
Commands to upload a lambda function to aws using aws cli
Zip up your project:
% zip –X –r ../index.zip *
or if you use 7zip
% 7z a ../index.zip *
Then the aws cli lets you upload:
% aws lambda update-function-code --function-name MyLambdaFunction --zip-file fileb://../index.zip
*****and maybe for you, the secret is
@vdeep
vdeep / irc.md
Created June 16, 2018 05:54 — forked from xero/irc.md
irc cheat sheet

#IRC Reference

Not intended as a guide for newbies, more like a "cheat sheet" for the somewhat experienced IRC user, especially one who wields some power over a channel.

##The Basics

  • /join #channel
    • Joins the specified channel.
  • /part #channel
    • Leaves the specified channel.