Skip to content

Instantly share code, notes, and snippets.

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

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
@aashari
aashari / 00 - Cursor AI Prompting Rules.md
Last active July 4, 2025 02:14
Cursor AI Prompting Rules - This gist provides structured prompting rules for optimizing Cursor AI interactions. It includes three key files to streamline AI behavior for different tasks.

Cursor AI Prompting Framework — Usage Guide

A disciplined, evidence-first workflow for autonomous code agents


1 · Install the Operational Doctrine

The Cursor Operational Doctrine (file core.md) encodes the agent’s always-on principles—reconnaissance before action, empirical validation over conjecture, strict command-execution hygiene, and zero-assumption stewardship.

@lucaswkuipers
lucaswkuipers / XCTestCase+trackForMemoryLeak.swift
Last active January 8, 2024 19:42
XCTestCase+trackForMemoryLeak
import XCTest
extension XCTestCase {
func assertDeallocated(
_ instance: AnyObject,
file: StaticString = #filePath,
line: UInt = #line
) {
addTeardownBlock { [weak instance] in
XCTAssertNil(
import UIKit
import Combine
protocol UIControlPublishable: UIControl {}
extension UIControlPublishable {
func publisher(for event: UIControl.Event) -> UIControl.InteractionPublisher<Self> {
return InteractionPublisher(control: self, event: event)
// I re-typed what I saw in reference 3 below,
// went to Liked videos page on YouTube[1] while logged in,
// pasted that into browser dev tools console (Google Chrome Version 97.0.4692.99 (Official Build) (x86_64)),
// pressed enter, and it seemed to do its thing, for the most part
// (when I refreshed the page, there was still 1 video remaining).
// [1] as of 2022-01-23 that’s at https://www.youtube.com/playlist?list=LL
// context: https://twitter.com/QiaochuYuan/status/1485164256970510340
// references:
@eneko
eneko / dealloc-breakpoint.md
Last active May 19, 2025 09:25
Xcode UIViewController dealloc breakpoint

Xcode deinit breakpoint for UIViewController

This breakpoint provides an easy way to track view controller deinitialization (deallocation) in UIKit-based applications. This can help finding memory leaks caused by retain cycles preventing view controllers from being deinitialized when dismissed or popped.

From Cédric Luthi's tweet in 2017:

Useful Xcode breakpoint. When you dismiss a controller and you don’t hear the pop sound (or see the log), you probably have a retain cycle.

@crewshin
crewshin / KeyboardAvoiding.swift
Last active July 18, 2024 20:39
KeyboardAvoiding SwiftUI
import SwiftUI
class KeyboardAvoidingHostingController<Content>: UIHostingController<Content> where Content: View {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
@OlexandrStepanov
OlexandrStepanov / ParseDERCertificate.swift
Created November 2, 2019 21:25
SecCertificate and SecKey from DER certificate in base64
let crtBase64 = "..."
if let certificateData = Data(base64Encoded: crtBase64, options: []),
let certificate = SecCertificateCreateWithData(nil, certificateData as CFData) {
// use certificate to initialize PinnedCertificatesTrustEvaluator, or ...
var trust: SecTrust?
let policy = SecPolicyCreateBasicX509()
let status = SecTrustCreateWithCertificates(certificate, policy, &trust)
@bocato
bocato / CoordinatorExtended.swift
Last active May 19, 2020 20:11
An extended implementation of the Coordinator pattern.
import UIKit
/// An enum that defines an output to be passed on from
/// a child to it's parents over the responders Chain
public protocol CoordinatorOutput {}
/// An enum that defines an input to be passed on from
/// the parent to it's children
public protocol CoordinatorInput {}
@bocato
bocato / CacheService.swift
Last active November 13, 2019 08:37
Simple Cache Service implementation
import Foundation
/// Defines the CacheService errors
///
/// - encryptionFailed: the key encription has failed
/// - couldNotSaveData: the data could not be saved
/// - couldNotLoadData: the data could not be loaded
/// - raw: some system error, not previously defined
public enum CacheServiceError: Error {
case encryptionFailed
@SitanHuang
SitanHuang / typeracer.hack.js
Last active April 1, 2024 05:26
Typeracer 100% hack (Version 2 - Aadaptive Mode - Types at minimum speed required to win)
function triggerKeyboardEvent(el, keyCode, type)
{
var eventObj = document.createEventObject ?
document.createEventObject() : document.createEvent("Events");
if(eventObj.initEvent){
eventObj.initEvent(type, true, true);
}
eventObj.keyCode = keyCode;