Skip to content

Instantly share code, notes, and snippets.

View lalkrishna's full-sized avatar
🤩

Lal Krishna lalkrishna

🤩
View GitHub Profile
@lalkrishna
lalkrishna / LKDebitCard.h
Last active July 11, 2019 09:46
DebitCard - Auto detect card type. Supported Cards: American Express, Discover, MasterCard, Visa Card
//
// LKDebitCard.m
// DebitCard
//
// Created by LK on 21/12/17.
// Copyright © 2017 LK. All rights reserved.
//
#import <Foundation/Foundation.h>
@lalkrishna
lalkrishna / CustomStringConvertible.swift
Created October 17, 2019 06:14
Extension for CustomStringConvertible to print All properties of a class
extension CustomStringConvertible {
var description: String {
var description: String = "\(type(of: self))("
let selfMirror = Mirror(reflecting: self)
if let superclassMirror = selfMirror.superclassMirror {
for child in superclassMirror.children {
if let propertyName = child.label {
description += "Super.\(propertyName): \(child.value), "
@lalkrishna
lalkrishna / UIViewShakeCategory.m
Created October 17, 2019 06:24
UIView error shaking animation.
- (void)shake {
[self _shake:10 direction:1 currentTimes:0 withDelta:5 speed:0.03 shakeDirection:ShakeDirectionHorizontal completion:nil];
}
- (void)_shake:(int)times direction:(int)direction currentTimes:(int)current withDelta:(CGFloat)delta speed:(NSTimeInterval)interval shakeDirection:(ShakeDirection)shakeDirection completion:(void (^)(void))completionHandler {
__weak UIView *weakSelf = self;
[UIView animateWithDuration:interval animations:^{
weakSelf.layer.affineTransform = (shakeDirection == ShakeDirectionHorizontal) ? CGAffineTransformMakeTranslation(delta * direction, 0) : CGAffineTransformMakeTranslation(0, delta * direction);
} completion:^(BOOL finished) {
if(current >= times) {
@lalkrishna
lalkrishna / Fastfile
Last active March 14, 2022 15:28
Fastfile configuration for take enterprise build iOS ipa and upload to diawi.
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
@lalkrishna
lalkrishna / Notes
Last active December 13, 2019 06:14
https://medium.com/swift2go/mastering-generics-with-protocols-the-specification-pattern-5e2e303af4ca
https://www.hackingwithswift.com/read/30/4/fixing-the-bugs-slow-shadows
https://www.raywenderlich.com/261-how-to-make-a-uiviewcontroller-transition-animation-like-in-the-ping-app#toc-anchor-007
https://medium.com/@phanquanghoang/using-gitlab-ci-cd-fastlane-for-ios-project-part-1-5e7db82a3566
https://developer.apple.com/documentation/metrickit/improving_your_app_s_performance/
extension UIApplication {
var topViewController: UIViewController? {
if #available(iOS 13.0, *) {
if UIApplication.shared.supportsMultipleScenes, let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
return keyWindow.visibleViewController
} else {
return UIApplication.shared.keyWindow?.visibleViewController
}
} else {
return UIApplication.shared.keyWindow?.visibleViewController
@lalkrishna
lalkrishna / StreamingFileReader.swift
Created June 30, 2020 10:52
If you need to read a very large file you’ll want to stream it so you’re not loading the entire thing into memory at once. Here’s a snippet for doing that.
class UseItHere {
func readFile() {
let fileReader = StreamingFileReader(path: logFile)
while let line = fileReader.readLine() {
// Do something with the line
}
}
}
class StreamingFileReader {
@lalkrishna
lalkrishna / UpdateManager.swift
Created July 18, 2020 10:26
Checking for Update in GitHub project release
struct UpdateManager {
let updateURL = "https://api.github.com/repos/{user_name}/{repo_title}/releases/latest"
static let shared = UpdateManager()
private init() { }
func checkForUpdates(updateAvailable: @escaping (String?) -> Void) {
let session = URLSession(configuration: .default)
let updateTask = session.dataTask(with: URL(string: updateURL)!) { (data, response, error) in
DispatchQueue.main.async {
guard let data = data else {
@lalkrishna
lalkrishna / GradientButton.dart
Created August 9, 2020 04:17
GradientButton Widget for Flutter Apps
import 'package:flutter/material.dart';
class GradientButton extends StatelessWidget {
final String title;
final VoidCallback onPressed;
const GradientButton({
Key key,
@required this.title,
@required this.onPressed,
}) : super(key: key);
@lalkrishna
lalkrishna / UIStoryboard+Extensions.swift
Created August 15, 2020 17:23
UIStoryboard Extension for Easy Instantiate Viewcontrollers [Swift]
enum Storyboard: String {
case main = "Main",
onboarding = "Onboarding"
}
protocol Instantiatable {
static var storyboard: Storyboard { get }
static func instantiate() -> Self
}