Skip to content

Instantly share code, notes, and snippets.

@hassanvfx
hassanvfx / versioned_tag.sh
Created October 20, 2024 20:23
Easily set the next semantic version
#!/bin/bash
# Ensure we are in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Not inside a git repository. Exiting."
exit 1
fi
# Get tags and sort them using version sort
TAGS=$(git tag | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" | sort -V)
@hassanvfx
hassanvfx / fetchObject.swift
Created January 29, 2024 15:18
Generic URLSession call
// Generic function to fetch and decode JSON into a Codable object
func fetchDecodedObject<T: Codable>(from urlString: String, completion: @escaping (Result<T, NetworkError>) -> Void) {
// Step 1: Create a URL instance
guard let url = URL(string: urlString) else {
completion(.failure(.badURL))
return
}
// Step 2: Create a URLSession
let session = URLSession.shared
@hassanvfx
hassanvfx / RouletteWheelView.swift
Created January 2, 2024 06:19
swiftui rouletter wheel
import SwiftUI
struct RouletteWheel: View {
let segments: [String]
var onResultSelected: (String) -> Void
@State private var rotationAngle: Double = 0
@State private var isSpinning: Bool = false
var body: some View {
ZStack {
@hassanvfx
hassanvfx / output_text.py
Created July 10, 2023 14:15
This script extract only the text from the twitter scraper
import csv
import sys
import os
import re
def remove_urls(text):
url_pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
return url_pattern.sub(r'', text)
def read_csv(filename, output_filename):
@hassanvfx
hassanvfx / QRCodeScanner.swift
Created June 23, 2023 02:04
SwiftUI QRCode Scanner
import SwiftUI
import AVFoundation
struct QRCodeScannerView: UIViewControllerRepresentable {
var handleQRCode: (String) -> Void
func makeUIViewController(context: Context) -> QRCodeScannerViewController {
let viewController = QRCodeScannerViewController()
viewController.handleQRCode = handleQRCode
@hassanvfx
hassanvfx / Quizz.swift
Created February 19, 2023 02:56
Quizz-sample
//
// QuizzView.swift
// TwinChatAI
//
// Created by Eon Fluxor on 2/18/23.
//
import Foundation
import SwiftUI
@hassanvfx
hassanvfx / convert2xcframework.sh
Created January 4, 2023 07:58
Convert Framework into XCFramework Xcode 14
#! /bin/bash
find "." -name '*.framework' -type d | while read -r FRAMEWORK
do
echo "-----------------------"
FRAMEWORK_NAME=$(echo "$FRAMEWORK" | sed 's/\.\/\(.*\)\.framework/\1/')
FRAMEWORK_BUNDLE_NAME=$(/usr/libexec/PlistBuddy -c "Print CFBundleName" "$FRAMEWORK/Resources/Info.plist") || exit
XCFRAMEWORK_ROOT="./_$FRAMEWORK_NAME.xcframework"
@hassanvfx
hassanvfx / cameraView.swift
Created January 4, 2023 05:24
Basic Camera Display / Buffer Analysis in SwiftUI
import SwiftUI
import AVFoundation
struct CameraView: View {
// Set up the AVCaptureSession and AVCaptureVideoPreviewLayer
let captureSession = AVCaptureSession()
let previewLayer = AVCaptureVideoPreviewLayer()
let cameraDelegate = CameraDelegate()
import UIKit
public class FactoryCache {
public typealias MakerClosure<Item> = ()->Item
typealias CacheType = NSCache<NSString, InstanceWrapper>
struct CacheWrapper{
var storage: CacheType = NSCache()
}
@hassanvfx
hassanvfx / largeTitleView.swift
Last active March 10, 2020 22:20
Access LargeTitleView in swift
var largeTitleView:UIView{
if let navBarSubviews = navigationController?.navigationBar.subviews {
for subView in navBarSubviews where NSStringFromClass(type(of: subView)).contains("LargeTitle"){
return subView
}
}
assert(false, "A large title view is expected on viewDidAppear")
return UIView()
}