Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
zorgiepoo / leaksucks.c
Created March 5, 2014 02:21
task_for_pid() leak when dev ID signed
// task_for_pid leak
// **IMPORTANT** To reproduce this bug, you have to sign this program with a developer ID -- do not use a self-signed certificate or run as root!
// This code will cause taskgated's memory usage to grow (see activity monitor)
// Link to Xcode project with included info.plist: http://tinyurl.com/kps28av
// Radar 16230826
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/mach_port.h>
@zorgiepoo
zorgiepoo / gist:34b9e787100572dd83c7
Created September 7, 2014 02:39
C++ destructors and ARC
#import "ZZGAppDelegate.h"
@interface Foo : NSObject
@end
@implementation Foo
- (void)dealloc
{
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;
cargo rustc --release -- -C no-stack-check -C target-cpu=native --emit llvm-ir
@zorgiepoo
zorgiepoo / protocol-generics.m
Last active August 29, 2015 14:27
Protocols break Obj-C generics in every sense (rdar://22204367)
@protocol M
@end
NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
NSNumber *bar = foo[0];
NSLog(@"%@", bar);
// No warnings
@zorgiepoo
zorgiepoo / copyfromnetworkvolume.m
Last active October 9, 2015 05:30
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..?)
// 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
template <typename T, typename P>
void ZGSearchWithFunctionHelperDirect(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataSize, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
//dataIndex is 'position' in the data, endLimit is (region_size) - (datatype_size)
//dataAlignment is amount to advance dataIndex for each iteration
while (dataIndex <= endLimit)
{
if (comparisonFunction(searchData, (T *)((int8_t *)bytes + dataIndex), searchValue))
{
P memoryAddress = (P)(address + dataIndex);
template <typename T, typename P>
void ZGSearchWithFunctionHelperDirect(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataSize, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
for (ZGMemorySize stepIndex = 0; stepIndex < maxSteps && dataIndex <= endLimit; stepIndex++)
{
template <typename T, typename P>
void ZGSearchWithFunctionHelperRegular(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
const ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
ZGMemorySize numberOfStepsToTake = MIN(maxSteps, (endLimit + dataAlignment - dataIndex) / dataAlignment);
@zorgiepoo
zorgiepoo / gist:7405858
Created November 11, 2013 00:24
Spinning progress indicator troubles, ugh
#import "ZGAppDelegate.h"
@interface ZGAppDelegate ()
@property (nonatomic) NSTimer *timer;
@property (assign) IBOutlet NSProgressIndicator *progressIndicator;
@end
@implementation ZGAppDelegate