Skip to content

Instantly share code, notes, and snippets.

Ahmed Hamdy dimohamdy

Block or report user

Report or block dimohamdy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View BookCollectionViewCell.swift
import UIKit
class BookCollectionViewCell: UICollectionViewCell {
var book: Book!
func configureCellWith(_ book: Book) { = book
View BookCollectionViewCell.swift
weak var viewControllerPreviewing: UIViewControllerPreviewing!
override func awakeFromNib() {
if self.traitCollection.forceTouchCapability == .available {
if viewControllerPreviewing != nil {
sourceVC.unregisterForPreviewing(withContext: viewControllerPreviewing)
viewControllerPreviewing = sourceVC.registerForPreviewing(with: self, sourceView: self)
View BookCollectionViewCell.swift
weak var sourceVC: UIViewController!
//make it weak to avoid retain cycle
func registerFor3DTouch(viewController: UIViewController?) {
if let viewController = viewController {
sourceVC = viewController
View BookCollectionViewCell.swift
class IqraaliCollectionViewCell: UICollectionViewCell {
var book: BookEntity!
extension BookCollectionViewCell: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
return AboutBookViewControllerWith(book)
View String+Extension.swift
import Foundation
extension String {
func fileName() -> String {
return URL(fileURLWithPath: self).deletingPathExtension().lastPathComponent
func fileExtension() -> String {
return URL(fileURLWithPath: self).pathExtension
View routes.swift
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
let imageResizeController = ImageResizeController()
try router.register(collection: imageResizeController)
View FilesHelper.swift
struct FilesHelper {
//get image path in Public folder
static func getImagePath(fileName:String) -> URL{
let directory = DirectoryConfig.detect()
let workingDirectory = directory.workDir
let workingDirectoryPath = URL(fileURLWithPath:workingDirectory)
let destination = workingDirectoryPath.appendingPathComponent("Public/\(fileName)")
return destination
View ImageResizeController.swift
import Vapor
import SwiftGD
final class ImageResizeController: RouteCollection {
func boot(router: Router) throws {
let routes = router.grouped("resize")
routes.get(use: index)
View Package.swift
.package(url: "", from: "2.0.0")
View Decode.swift
let jsonString = """
"id": 1,
"name": "yearly.plan",
"display_name": "الباقة اليومية",
"payment_method_key": "1",
"number_of_days": "35",
"payment_method_id": 3
You can’t perform that action at this time.