Skip to content

Instantly share code, notes, and snippets.

View mdippery's full-sized avatar
💭
Have you seen an older me go by in a time machine?

Michael Dippery mdippery

💭
Have you seen an older me go by in a time machine?
View GitHub Profile
@mdippery
mdippery / group.m
Created June 30, 2015 06:20
Get file's group name in Cocoa
#import <Foundation/Foundation.h>
#include <grp.h>
#include <string.h>
#include <sys/stat.h>
@interface FileOwnerManager : NSObject
- (BOOL)isWheelPresent:(NSString *)path;
@end
@implementation FileOwnerManager
#import <Foundation/Foundation.h>
#import <stdio.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *s1 = @"foo";
NSString *s2 = @"foo";
NSString *s3 = [[NSString alloc] initWithString:@"foo"];
#import <Foundation/Foundation.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *json = @"DUMMY({parameters:{code:\"60246\", language:\"en\", country:\"en\"}, result:{\"...JSON...});";
NSUInteger rangeStart = [json rangeOfString:@"result:"].location;
NSUInteger lastBrace = [json rangeOfString:@"}" options:NSBackwardsSearch].location;
NSUInteger jsonStart = rangeStart + [@"result:" length];
#import <Foundation/Foundation.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *json = @"DUMMY({parameters:{code:\"60246\", language:\"en\", country:\"en\"}, result:{\"...JSON...});";
NSUInteger rangeStart = [json rangeOfString:@"result:"].location;
NSString *justJson = [json substringFromIndex:rangeStart + [@"range:" length]];
NSUInteger lastBrace = [justJson rangeOfString:@"}" options:NSBackwardsSearch].location;
#include <stdio.h>
struct base {
int foo;
};
struct derived {
int foo;
char *bar;
};
@mdippery
mdippery / fabric.sh
Created October 4, 2010 19:22
A bash completion script for Fabric targets
# A bash completion script for Fabric targets
# Author: Michael Dippery <mdippery@gmail.com>
_complete_fabric() {
COMPREPLY=()
if [ -e ./fabfile.py ]; then
local targets=$(fab -l | sed '1,2d' | awk '{print $1}')
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) )
fi
@mdippery
mdippery / fail.c
Created November 19, 2010 20:10
For those times when you type `fail -t` instead of `tail -f`
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
fprintf(stderr,
" FAIL WHALE! \n"
@mdippery
mdippery / NSNullCheck.m
Created November 19, 2010 22:40
Rails' nil?, for Objective-C
#import <Foundation/Foundation.h>
@interface NSObject (NSNullCheck)
- (BOOL)isNull;
@end
@implementation NSObject (NSNullCheck)
- (BOOL)isNull { return NO; }
@end
@mdippery
mdippery / FileTailer.m
Created January 12, 2011 23:02
A class that mimics `tail -f`
//
// Created by Michael Dippery on 1/12/2011.
// Copyright 2011 Michael Dippery. All rights reserved.
//
#import "FileTailer.h"
@implementation FileTailer
- (id)initWithPath:(NSString *)path refreshPeriod:(NSTimeInterval)aRefresh
@mdippery
mdippery / sort-string.m
Created March 31, 2011 17:21
String sorting example in Objective-C
#import <Foundation/Foundation.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static int compare_char(const char *a, const char *b)
{
if (*a > *b) {
return 1;
} else if (*a < *b) {