Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
zorgiepoo / printf_ex.idr
Last active Dec 20, 2017
Type-safe printf in Idris including a practical run-time validation example -- https://zgcoder.net/ramblings/typesafe-printf.html
View printf_ex.idr
%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 "")
View ui-tests
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.
View cocoasux.m
// 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)];
View decode.swift
// This uses a legacy version of swift
import Foundation
class Model: NSObject, NSSecureCoding {
let bar: String
init(bar: String) {
self.bar = bar
}
@zorgiepoo
zorgiepoo / copyfromnetworkvolume.m
Last active Oct 9, 2015
Can't figure out how to copy a symbolic link, or a directory containing a symbolic link, that is originating on a different Network Volume (eg: in my case it's via AFP, or is it SMB2 these days..?)
View copyfromnetworkvolume.m
// Note that on the command line cp -R /Volumes/mayur/bar.txt /Users/msp/Desktop/bar.txt
// works just fine; the symbolic link is copied, and it's not followed
// But I have *no idea* how to do this programatically as shown below
// (Note: My end goal is being able to copy an app from a volume to my local disk, but
// it fails when it encounters a symbolic link)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSURL *sourceURL = [NSURL fileURLWithPath:@"/Volumes/mayur/bar.txt"]; // this is a symbolic link
NSURL *destinationURL = [NSURL fileURLWithPath:@"/Users/msp/Desktop/bar.txt"];
// this outputs 1, so the source does exist
@zorgiepoo
zorgiepoo / protocol-generics.m
Last active Aug 29, 2015
Protocols break Obj-C generics in every sense (rdar://22204367)
View protocol-generics.m
@protocol M
@end
NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
NSNumber *bar = foo[0];
NSLog(@"%@", bar);
// No warnings
View gist:14a0a36d65c29dcfdeb9
cargo rustc --release -- -C no-stack-check -C target-cpu=native --emit llvm-ir
@zorgiepoo
zorgiepoo / gist:5f769893ad2a7f58a747
Last active Feb 11, 2018
Game speed hack prototype; still WIP
View gist:5f769893ad2a7f58a747
#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
View gist:21188981e90b2a9641d2
function xman
set lookup_name "$argv[-1]"
set lookup_section "$argv[1]"
set open_string ""
set grep_string ""
set beginning_pattern "(^|[ \t\r\n\f])"
if [ $lookup_name = $lookup_section ]; set open_string "x-man-page://$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\("; end;
if [ $lookup_name != $lookup_section ]; set open_string "x-man-page://$lookup_section/$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\($lookup_section\\)"; end;
View gist:34b9e787100572dd83c7
#import "ZZGAppDelegate.h"
@interface Foo : NSObject
@end
@implementation Foo
- (void)dealloc
{
You can’t perform that action at this time.