Skip to content

Instantly share code, notes, and snippets.

@oalansari82
oalansari82 / iterm2-solarized.md
Created Aug 6, 2021 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)
View iterm2-solarized.md

Default

Default

Powerlevel10k

Powerlevel10k

@oalansari82
oalansari82 / swiftui-resize-image-and-maintain-aspect-ratio.swift ViewModifier for resizing images in SwiftUI. Resize an image to any size (square, circle, rectangle) while maintaining its aspect ratio.
View swiftui-resize-image-and-maintain-aspect-ratio.swift
import SwiftUI
/// Common aspect ratios
public enum AspectRatio: CGFloat {
case square = 1
case threeToFour = 0.75
case fourToThree = 1.75
}
/// Fit an image to a certain aspect ratio while maintaining its aspect ratio
@oalansari82
oalansari82 / UIView+Extension.swift
Created Jul 5, 2020
How to dismiss the keyboard by tap
View UIView+Extension.swift
extension UIView {
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
UIApplication.shared.windows
.first { $0.isKeyWindow }?
.endEditing(true)
}
}
@oalansari82
oalansari82 / PhotoPicker.swift
Last active Jul 5, 2020
PHPicker multi image selection SwiftUI Implementation
View PhotoPicker.swift
import SwiftUI
import PhotosUI
struct PhotoPicker: UIViewControllerRepresentable {
typealias UIViewControllerType = PHPickerViewController
@Binding var images: [UIImage]
var selectionLimit: Int
var filter: PHPickerFilter?
@oalansari82
oalansari82 / AdaptsToSoftwareKeyboard.swift
Created Jun 6, 2020 — forked from scottmatthewman/AdaptsToSoftwareKeyboard.swift
An example of using Combine to automatically adapt a SwiftUI scrollable view to accommodate an iOS onscreen keyboard
View AdaptsToSoftwareKeyboard.swift
import SwiftUI
import Combine
struct AdaptsToSoftwareKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
content
.padding(.bottom, currentHeight)
.edgesIgnoringSafeArea(.bottom)
View swift.swift
let attributedString = NSMutableAttributedString(string: "WhatEver text you want")
// *** Create instance of `NSMutableParagraphStyle`
let paragraphStyle = NSMutableParagraphStyle()
// *** set LineSpacing property in points ***
paragraphStyle.lineSpacing = 4 // Whatever line spacing you want in points
// *** Apply attribute to string ***
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
@oalansari82
oalansari82 / FirebaseAuthExtention.swift
Created May 27, 2018
Firebase Auth & Storage Error Handling for iOS
View FirebaseAuthExtention.swift
// MARK: - Firebase Auth
extension Auth {
//Handle Firebase Auth Errors
static func handleFirebaseAuthErrorWith(errorCode: AuthErrorCode) -> [String] {
switch errorCode {
case .emailAlreadyInUse:
let title = "User Exist"
let message = "The email address provided already exist. Please login using your credentials."
return [title, message]
case .invalidEmail:
@oalansari82
oalansari82 / viewDidLoad.swift
Last active May 25, 2018
Replace NavigationController's title with a logo
View viewDidLoad.swift
// Here you can set View width and height as per your requirement for displaying supportView position in navigationbar
let supportView = UIView(frame: CGRect(x: 0, y: 0, width: 120, height: 40))
//supportView.backgroundColor = UIColor.red
let logo = UIImageView(image: UIImage(named: "logo")) //UIImage(named: "SelectAnAlbumTitleLettering")
// customize the origin as (45,5) but can pass them as your requirement.
logo.frame = CGRect(x: 0, y: -5, width: supportView.frame.size.width, height: supportView.frame.size.height)
supportView.addSubview(logo)
supportView.contentMode = .center
View PDFTools.swift
class PdfTools {
func generatePdfFromCollectionView(_ collectionView: UICollectionView?, filename:String, success:(String) -> ()) {
guard let collectionView = collectionView else {
return
}
let pdfData = NSMutableData()
let contentArea = CGRect(
@oalansari82
oalansari82 / functions.php
Last active Mar 30, 2018
Add body class based on browser
View functions.php
<?php
// Only add the content below this line
add_filter('body_class','browser_body_class');
/**
*
* Add browser class based on user browser
*
*/
function browser_body_class($classes) {