Skip to content

Instantly share code, notes, and snippets.

View cedricbahirwe's full-sized avatar
📈
Small things in a Great way

Cédric Bahirwe cedricbahirwe

📈
Small things in a Great way
View GitHub Profile
@cedricbahirwe
cedricbahirwe / myEmojicode.emojic
Created September 27, 2020 22:48
This is ta simple conditional logic Using EmojiCode
🏁 🍇
150 ➡️ offer
100 ➡️ minPrice
200 ➡️ maxPrice
💭 Edit the condition below:
↪️ 🤜 offer ▶️ minPrice 🤛 🤝 🤜 offer ◀️ maxPrice 🤛 🍇
😀 🔤Offer accepted!🔤❗️
🍉
import Foundation
// The life of a developer using Phantom Types
enum Eating {}
enum Coding {}
enum Sleeping {}
struct Transition<From, To> { }
@cedricbahirwe
cedricbahirwe / LocalStorageProperyWrapper.swift
Created July 20, 2021 11:11
An implementation of Property Wrapper used to store data in UserDefaults in swift.
@propertyWrapper
struct LocalStorage<T: Codable> {
private let userDefaults: UserDefaults = .standard
private let key: String
private let defaultValue: T
init(wrappedValue defaultValue: T, key: String) {
self.key = key
self.defaultValue = defaultValue
}
@cedricbahirwe
cedricbahirwe / UIDynamicAnimator.swift
Created July 25, 2021 14:11
A simple prototype using `UIDynamicAnimator`
class ViewController: UIViewController {
var animator: UIDynamicAnimator?
var origins: [(String, CGPoint)] = []
let range: ClosedRange<CGFloat> = 0.0...255.0
var message = "This is cedric trying to animate the components with gravity"
override func viewDidLoad() {
@cedricbahirwe
cedricbahirwe / PassCodeCodeView.swift
Created August 15, 2021 21:49
OneTime Code SwiftUI Wrapper Customizable View
struct PassCodeCodeView: UIViewRepresentable {
init(_ count: Int = 5,
width: CGFloat,
height: CGFloat,
spacing: CGFloat = 10,
action: @escaping (String) -> ()) {
self.width = width
self.height = height
self.spacing = spacing
@cedricbahirwe
cedricbahirwe / DebuggingResource.swift
Created August 18, 2021 20:18
A simple helper for debugging my networking requests, response and status code😀.
class DebuggingResource: NSObject {
private static func printLine(_ line: String) {
print("--- \(line) ---")
}
public static func logJsonDataFormat(_ data: Data) {
printLine("Start Debugging Json Format")
if let json = try? JSONSerialization.jsonObject(with: data) {
@cedricbahirwe
cedricbahirwe / DraggableAnnotationView.swift
Created August 18, 2021 23:26
A DraggableAnnotationView in MapBox
class DraggableAnnotationView: MGLAnnotationView {
var didSetNewCoord: (CLLocationCoordinate2D) -> Void = { _ in }
init(reuseIdentifier: String, size: CGFloat, didSetCoord: @escaping(CLLocationCoordinate2D) -> Void) {
self.didSetNewCoord = didSetCoord
super.init(reuseIdentifier: reuseIdentifier)
// `isDraggable` is a property of MGLAnnotationView, disabled by default.
isDraggable = true
@cedricbahirwe
cedricbahirwe / DebuggingResource.swift
Created September 9, 2021 08:02
A monolithic class for printing logs when dealing with Networking
class DebuggingResource: NSObject {
private static func printLine(_ line: String) {
print("--- \(line) ---")
}
public static func logJsonDataFormat(_ data: Data) {
printLine("Start Debugging Json Format")
if let json = try? JSONSerialization.jsonObject(with: data) {
@cedricbahirwe
cedricbahirwe / TopSideBarView.swift
Created September 13, 2021 08:02
A Simple Top SideBar View in SwiftUI
import SwiftUI
struct TopSideBarView: View {
private enum Constants {
static let foregrounColor = Color(.systemBackground)
static let backgroundColor = Color(.label).opacity(0.9)
static let avatarMinSize: CGFloat = 60
// Answer to https://stackoverflow.com/questions/69929331/current-time-is-not-displayed-in-the-analog-view
struct Hand: Shape {
let inset: CGFloat
let angle: Angle
func path(in rect: CGRect) -> Path {
let rect = rect.insetBy(dx: inset, dy: inset)
var path = Path()
path.move(to: CGPoint(x: rect.midX, y: rect.midY))
path.addRoundedRect(in: CGRect(x: rect.midX - 4, y: rect.midY - 4, width: 8, height: 8), cornerSize: CGSize(width: 8, height: 8))