Skip to content

Instantly share code, notes, and snippets.

View X901's full-sized avatar

Basel Baragabah X901

View GitHub Profile
@JacquesDuflos
JacquesDuflos / mangakatana_cbz_creater
Last active May 17, 2024 13:14
Makes cbz files for each chapter of a manga downloaded form mangakatana.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import zipfile
'''
this script is ment to turn .zip files downloaded from mangakatana.com to a serie
of .cbz files. The .zip files contain usually 10 chapters of a same manga stored as
a serie of folders.
'''
@pmstani
pmstani / View.swift
Created March 17, 2023 07:30
Photo picker using fullscreencover in SwiftUI
import SwiftUI
import PhotosUI
struct ContentView: View {
@State var showPhotoPicker = false
@State var selectedImage: UIImage?
var body: some View {
VStack {
if let image = selectedImage {
@wingovers
wingovers / About.md
Last active November 5, 2022 20:55
Transparent SwiftUI view clipped, cropped screenshot returned as UIImage (draft)

Had the darnedest time get the origin set correctly.

A few things that weren't obvious (to me at least):

  1. Convert the target child view to a UIHostingView, not self or body, otherwise your origin will be inexplicably quite off and screenshot will look drunk.
  2. Add +1 to the origin's y-axis, at least on the iPhone XS, because of course. Otherwise see above.
  3. A drawing group must be applied within the background modifier of your view, if your view has a background. Otherwise what's below bleeds through. And if you apply that else where that hierarchy disappears.
  4. In UIGraphics, override the background color to clear. UIHostingView conveniently resets the background to the system background color after the graphic returns. If you don't do this, within UIGraphics you can layer things transparently behind the UIView, but the readout back to SwiftUI will not be the cropped droid you were looking for.
  5. Scale and rotate do not work together as ExclusiveGestures. Ok.
  6. All the gestures perform for the us
@Amzd
Amzd / UIKitTabView.swift
Last active March 16, 2024 10:40
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem
/**
* The $1 Unistroke Recognizer
*
* Jacob O. Wobbrock, Ph.D.
* The Information School
* University of Washington
* Seattle, WA 98195-2840
* wobbrock@uw.edu
*
* Andrew D. Wilson, Ph.D.
@izzuddin91
izzuddin91 / convertPDFToImage.swift
Created July 29, 2018 03:59
general code snippets
//swift 4.0
func convertpdfToImage(url: URL) -> UIImage? {
guard let document = CGPDFDocument(url as CFURL) else { return nil }
guard let page = document.page(at: 1) else { return nil }
let pageRect = page.getBoxRect(.mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let img = renderer.image { ctx in
UIColor.white.set()
ctx.fill(pageRect)
@verebes1
verebes1 / RealmCascadeDeletion.swift
Last active March 6, 2024 19:47
Realm Cascade Deletion in Swift
import RealmSwift
import Realm
protocol CascadeDeleting {
func delete<S: Sequence>(_ objects: S, cascading: Bool) where S.Iterator.Element: Object
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
extension Realm: CascadeDeleting {
func delete<S: Sequence>(_ objects: S, cascading: Bool) where S.Iterator.Element: Object {
@sarpsolakoglu
sarpsolakoglu / SimpleClient.swift
Last active June 30, 2020 16:38
Simple Swift 4 Rest Client that uses the Codable protocol for JSON conversion
//
// SimpleClient.swift
//
// Created by Sarp Solakoglu on 18/09/2017.
// Copyright © 2017 Sarp Solakoglu. All rights reserved.
//
import Foundation
enum RestMethod: String {
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 15, 2024 18:34
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@tempire
tempire / swift_draw_image_on_pdf.swift
Created April 25, 2015 09:24
swift draw image on pdf
func drawOnPDF(path: String) {
// Get existing Pdf reference
let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path))
// Get page count of pdf, so we can loop through pages and draw them accordingly
let pageCount = CGPDFDocumentGetNumberOfPages(pdf);
// Write to file
UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil)