Skip to content

Instantly share code, notes, and snippets.

View BenziAhamed's full-sized avatar
🏠
Working from home

Benzi BenziAhamed

🏠
Working from home
  • Meta
  • London, UK
View GitHub Profile
@BenziAhamed
BenziAhamed / Shortcut.swift
Created February 8, 2023 16:18
Parsing and rendering macOS shortcuts
import Cocoa
fileprivate let modifierMap = [
"cmd": "⌘",
"command": "⌘",
"shift": "⇧",
"control": "^",
"ctrl": "^",
"opt": "⌥",
"option": "⌥",
@BenziAhamed
BenziAhamed / ChatRoom.swift
Created February 27, 2019 12:41
Simulates a chat room
import Cocoa
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
struct ChatMessage {
let id: String
let senderId: String
let message: String
let timestamp: Double
@BenziAhamed
BenziAhamed / Obfuscator.swift
Created November 15, 2018 16:00 — forked from DejanEnspyra/Obfuscator.swift
Obfuscation of hard-coded security-sensitive strings.
//
// Obfuscator.swift
//
// Created by Dejan Atanasov on 2017-05-31.
//
import Foundation
class Obfuscator: AnyObject {
import Cocoa
// what is a 'type'?
// it has a domain, a name
// it can have 'properties'
protocol TypeBuilder : class {
func setType(type: String)
func setTypeName(name: String)
func addProperty(type: String, label: String)
@BenziAhamed
BenziAhamed / Memcache.swift
Created May 17, 2017 13:27
In-process, single thread safe memcache in Swift
import Foundation
public struct Memcache {
enum Expiration {
case never
case at(Double)
var expired: Bool {
switch self {
case .never: return false
@BenziAhamed
BenziAhamed / CIFilterChain.swift
Last active May 27, 2022 15:00
CIFilterChain - Chain together CI filters with a fluent API
//: Playground - noun: a place where people can play
import UIKit
public protocol CIFilterChainable {
var cifilter: CIFilter? { get }
}
extension String : CIFilterChainable {
public var cifilter: CIFilter? {
@BenziAhamed
BenziAhamed / DynamicTree.swift
Created January 28, 2017 17:32
Swift port of Box2D's dynamic AABB tree
//
// DynamicTree.swift
// Mojumbo
//
// Created by Benzi on 10/12/16.
//
// Swift port of the Box2D implemention of a dynamic balancing AABB tree
// https://github.com/erincatto/Box2D/blob/master/Box2D/Box2D/Collision/b2DynamicTree.h
@BenziAhamed
BenziAhamed / Templater.swift
Created January 18, 2017 23:33
My lame little templating engine in Swift
import Cocoa
// more of a POC
// not production ready
protocol PropertyReflectable { }
extension PropertyReflectable {
subscript(property key: String) -> Any? {
let mirror = Mirror(reflecting: self)
@BenziAhamed
BenziAhamed / XML.swift
Created October 15, 2015 19:42
Example XML processing
//: Playground - noun: a place where people can play
import UIKit
let xml = "<coord2 count=\"3\">"
+ "<markers>"
+ "<marker>"
+ "<item>marker1</item>"
+ "</marker>"
@BenziAhamed
BenziAhamed / CGCreatePattern.swift
Last active May 24, 2022 22:24
Demonstration of using CGCreatePattern in Swift
//: Playground - noun: a place where people can play
//: Copy this to one!
import UIKit
// With helpful insights from
// https://forums.developer.apple.com/message/15725#15725 via http://oleb.net/blog/2015/06/c-callbacks-in-swift/
// This is essential the standalone basic definition of a pattern
// that CGCreatePattern requires