Skip to content

Instantly share code, notes, and snippets.

// This uses a legacy version of swift
import Foundation
class Model: NSObject, NSSecureCoding {
let bar: String
init(bar: String) {
self.bar = bar
}
// I'm not using the passed editRange and delta because I've found them to be quite misleading...
// This happens to be a new API (macOS 10.11) so maybe it's not really battle tested or I don't know what I'm doing
// Either way I'd like to support older systems so for portability sake it's easier to not use these parameters
- (void)textStorage:(NSTextStorage *)textStorage didProcessEditing:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)__unused delta
{
if ((editedMask & NSTextStorageEditedCharacters) != 0)
{
//[self updateTextProcessingForTextStorage:textStorage];
//NSLog(@"Edited range: %lu, %lu", editedRange.location, editedRange.length);
[textStorage removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0, textStorage.length)];
@zorgiepoo
zorgiepoo / ui-tests
Last active December 24, 2016 00:45
Unable to run UI Tests because Xcode Helper does not have permission to use Accessibility.
To enable UI testing, go to the Security & Privacy pane in System Preferences, select the Privacy tab,
then select Accessibility, and add Xcode Helper to the list of applications allowed to use Accessibility.
@zorgiepoo
zorgiepoo / printf_ex.idr
Last active December 20, 2017 20:14
Type-safe printf in Idris including a practical run-time validation example -- https://zgcoder.net/ramblings/typesafe-printf.html
%default total
Prefix : Type
Prefix = String
data Format = Number Prefix Format | Str Prefix Format | End Prefix
parse : List Char -> String -> Format
parse [] prefix_acc = End prefix_acc
parse ('%' :: 'd' :: xs) prefix_acc = Number prefix_acc (parse xs "")
@zorgiepoo
zorgiepoo / gist:5f769893ad2a7f58a747
Last active February 11, 2018 16:12
Game speed hack prototype; still WIP
#Game Speed Hack
#Increase x86-64 game by 2x by overriding mach_absolute_time
#May not work on games that call gettimeofday or something else instead
#May not work on games that don't call a time function at all (these areee badddd)
#May also not work if the function is referenced in more than one executable image (eg, local library)
#This is not very robust
from bitslicer import VirtualMemoryError, DebuggerError
import vmprot
SPEED_MULTIPLIER = 2.0
@zorgiepoo
zorgiepoo / osx_being_debugged.c
Created April 12, 2014 20:40
Detect if you're being debugged on OS X. Apple's AmIBeingDebugged() won't handle a debugger not using ptrace and is insufficient.
#include <mach/task.h>
#include <mach/mach_init.h>
#include <stdbool.h>
static bool amIAnInferior(void)
{
mach_msg_type_number_t count = 0;
exception_mask_t masks[EXC_TYPES_COUNT];
mach_port_t ports[EXC_TYPES_COUNT];
exception_behavior_t behaviors[EXC_TYPES_COUNT];
@zorgiepoo
zorgiepoo / gist:d751cba19a0167a589a2
Last active October 21, 2023 07:54
Example program for retrieving active URLs from Safari webkit processes.
#import <Foundation/Foundation.h>
// Useful references:
// -[SMProcess webKitActiveURLs] implementation used in Activity Monitor on 10.9 (search for it using Hopper)
// http://opensource.apple.com/source/WebKit2/WebKit2-7537.71/WebProcess/mac/WebProcessMac.mm
// https://github.com/rodionovd/RDProcess/blob/master/RDProcess.m
const CFStringRef kLSActivePageUserVisibleOriginsKey = CFSTR("LSActivePageUserVisibleOriginsKey");
const int kLSMagicConstant = -1;