Skip to content

Instantly share code, notes, and snippets.

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

Default

Default

Powerlevel10k

Powerlevel10k

@oalansari82
oalansari82 / swiftui-resize-image-and-maintain-aspect-ratio.swift
Created July 9, 2021 15:23 — forked from karigrooms/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.
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 July 5, 2020 16:00
How to dismiss the keyboard by tap
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 March 21, 2023 04:02
PHPicker multi image selection SwiftUI Implementation
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 June 6, 2020 20:43 — forked from scottmatthewman/AdaptsToSoftwareKeyboard.swift
An example of using Combine to automatically adapt a SwiftUI scrollable view to accommodate an iOS onscreen keyboard
import SwiftUI
import Combine
struct AdaptsToSoftwareKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
content
.padding(.bottom, currentHeight)
.edgesIgnoringSafeArea(.bottom)
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 11:28
Firebase Auth & Storage Error Handling for iOS
// 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 13:06
Replace NavigationController's title with a logo
// 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
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 March 30, 2018 09:45
Add body class based on browser
<?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) {