Skip to content

Instantly share code, notes, and snippets.

CocoaBeans / gdbinit
Created Feb 21, 2012
.gdbinit - A user-friendly gdb configuration file
View gdbinit
# INSTALL INSTRUCTIONS: save as ~/.gdbinit
# DESCRIPTION: A user-friendly gdb configuration file.
# REVISION : 7.3 (16/04/2010)
# CONTRIBUTORS: mammon_, elaine, pusillus, mong, zhang le, l0kit,
# truthix the cyberpunk, fG!, gln
SCRIPT_DIR=`cd "${SCRIPT_DIR}"; pwd`
echo "$SCRIPT_DIR"
CocoaBeans / 4CF.c
Created Jul 7, 2016 — forked from daurnimator/4CF.c
Use your own main loop on OSX
View 4CF.c
#include <mach/port.h> /* mach_port_t */
#include <mach/mach.h> /* mach_port_allocate(), mach_task_self(), mach_port_insert_member() */
#include <sys/event.h> /* kqueue(), kevent64(), struct kevent64_s, EVFILT_MACHPORT, EV_SET64, EV_ADD */
#include <sys/time.h> /* struct timespec */
//#include <dispatch/private.h>
extern mach_port_t _dispatch_get_main_queue_port_4CF(void);
extern void _dispatch_main_queue_callback_4CF(void);
#include <stdio.h>
CocoaBeans / .gitignore
Last active Dec 28, 2015
Basic .gitignore
View .gitignore
# OS X Finder
# Xcode per-user config
# for LocalizableStringsIn in $(find "${PROJECT_DIR}"/Languages -name "" -print)
# do
# LocalizableStrings="${LocalizableStringsIn/}"
# iconv -f UTF-8 -t UTF-16BE < "${LocalizableStringsIn}" > "${LocalizableStrings}"
# done
# NEEDLE='\( -path "*.lproj/*.strings" \! \( -path "*/build/*" \) \)'
CocoaBeans / OOPinC.c
Last active Dec 23, 2015
OOP in C Example
View OOPinC.c
struct {
int (*AND_function_ptr)(int, int);
int (*math_funct_ptr)(float, char, float);
int (*comp_funct_ptr)(double);
int (*regul_funct_ptr)(char*, char*, int);
int AND_function (int parameter1, int parameter2)
CocoaBeans / GetRunningBSDProcesses.m
Created Sep 8, 2013
Returns a list of running BSD processes efficiently using sysctl
View GetRunningBSDProcesses.m
/* This returns the full process name, rather than the 16 char limit
the p_comm field of the proc struct is limited to.
Note that this only works if the process is running under the same
user you are, or you are running this code as root. If not, then
the p_comm field is used (this function returns nil).
NSString *GetNameForProcessWithPID(pid_t pidNum)
NSString *returnString = nil;
CocoaBeans / gist:6074002
Created Jul 24, 2013
Quickie for -[NSString stringWithFormat:...] just throw the following in a header.... #define $(...) ((NSString *)[NSString stringWithFormat:__VA_ARGS__,nil]) and then use like [$(@"whatever%ld %@", 2, obj ) stringByRemoving......]
View gist:6074002
#define $(...) ((NSString *)[NSString stringWithFormat:__VA_ARGS__,nil])
// use like so...[$(@"whatever%ld %@", 2, obj ) stringByRemoving......
CocoaBeans / PrintStackTrace.c
Created Apr 30, 2013
Print a symbolicated stack trace
View PrintStackTrace.c
#import <execinfo.h>
#import <stdio.h>
void PrintStackTrace(void)
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s\n", strs[i]);
CocoaBeans / gist:5054672
Created Feb 28, 2013
List logged in *console* users on MacOS X
View gist:5054672
#import <Foundation/Foundation.h>
#import <utmpx.h>
// CCFLAGS="-std=c99 -framework Foundation -arch i386 -mmacosx-version-min=10.6"
NSSet *ConsoleUsers(void)
NSMutableSet *userList = [NSMutableSet set];
struct utmpx *userTmp = getutxent();