Skip to content

Instantly share code, notes, and snippets.

View kafran's full-sized avatar
🏠
WFH

Kolmar Kafran kafran

🏠
WFH
View GitHub Profile
@kafran
kafran / ApiKey.swift
Created May 3, 2023 13:25
Using iCloud for storing keys and then pushing into keychain of device.
import CloudKit
import Foundation
import Locksmith
/**
API Key used by this app is fetched from CloudKit. This class manages fetching and saving it into Keychain
*/
class ApiKey {
private static let RECORD_NAME = <# RECORD_NAME_IN_CLOUDKIT #>
private static let KEY = <# KEY_NAME_IN_CLOUDKIT #>
import SwiftUI
// pre-create one instance of MeasurementFormatter for our format needs
// re-use as needed
extension MeasurementFormatter {
static private let formatter: MeasurementFormatter = {
let formatter = MeasurementFormatter()
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.minimumFractionDigits = 2
@kafran
kafran / CVPixelBufferPixelFormatNames.swift
Created January 23, 2023 20:56 — forked from skyebook/CVPixelBufferPixelFormatNames.swift
Easily get the pixel format name of a CVPixelBuffer
public func CVPixelBufferGetPixelFormatName(pixelBuffer: CVPixelBuffer) -> String {
let p = CVPixelBufferGetPixelFormatType(pixelBuffer)
switch p {
case kCVPixelFormatType_1Monochrome: return "kCVPixelFormatType_1Monochrome"
case kCVPixelFormatType_2Indexed: return "kCVPixelFormatType_2Indexed"
case kCVPixelFormatType_4Indexed: return "kCVPixelFormatType_4Indexed"
case kCVPixelFormatType_8Indexed: return "kCVPixelFormatType_8Indexed"
case kCVPixelFormatType_1IndexedGray_WhiteIsZero: return "kCVPixelFormatType_1IndexedGray_WhiteIsZero"
case kCVPixelFormatType_2IndexedGray_WhiteIsZero: return "kCVPixelFormatType_2IndexedGray_WhiteIsZero"
case kCVPixelFormatType_4IndexedGray_WhiteIsZero: return "kCVPixelFormatType_4IndexedGray_WhiteIsZero"
@kafran
kafran / MyCoredataObject+CoreDataProperties.swift
Created December 5, 2022 23:10 — forked from novinfard/MyCoredataObject+CoreDataProperties.swift
[Auto increment in Core Data] How to implement auto-increment in core data while saving it #coredata
import Foundation
import CoreData
extension MyCoredataObject {
@nonobjc public class func createFetchRequest() -> NSFetchRequest<MyCoredataObject> {
return NSFetchRequest<MyCoredataObject>(entityName: "MyCoredataObject")
}
@NSManaged public var sortId: Int64
@kafran
kafran / gist:7ba2500591b84eb5641df9f8a90dd4c2
Created May 30, 2020 00:33 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.


Updated Apr 5 2019:

because this is a gist from 2011 that people stumble into and maybe you should AES instead of 3DES in the year of our lord 2019.

some other notes:

@kafran
kafran / tmux-cheatsheet.markdown
Created April 26, 2020 04:24 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@kafran
kafran / 01_add_extra_repos.sh
Last active October 10, 2017 02:14 — forked from xenialaq/essential_packages.sh
Ubuntu Setup (Ubuntu MATE 17.04)
#!/bin/bash
cd /tmp && \
/usr/lib/apt/apt-helper download-file http://debian.sur5r.net/i3/pool/main/s/sur5r-keyring/sur5r-keyring_2017.01.02_all.deb keyring.deb SHA256:4c3c6685b1181d83efe3a479c5ae38a2a44e23add55e16a328b8c8560bf05e5f && \
sudo dpkg -i ./keyring.deb && \
echo "deb http://debian.sur5r.net/i3/ $(grep '^DISTRIB_CODENAME=' /etc/lsb-release | cut -f2 -d=) universe" | sudo tee /etc/apt/sources.list.d/sur5r-i3.list && \
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886 0DF731E45CE24F27EEEB1450EFDC8610341D9410 && \
echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list && \
sudo apt-get update && \
foo bar baz
a 1
b 2
c
4
e 5