Skip to content

Instantly share code, notes, and snippets.

@CocoaBeans
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);
}functions;
int AND_function (int parameter1, int parameter2)
{
}
@CocoaBeans
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
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
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
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();
@CocoaBeans
CocoaBeans / gist:4758423
Created Feb 11, 2013
Rebuild the LaunchServices database
View gist:4758423
#!/bin/bash
LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
echo "Rebuilding LaunchServices database..."
"${LSREGISTER}" -kill -r -all system,local,user
echo "Done."
@CocoaBeans
CocoaBeans / LSQuarantineEvent.command
Last active Dec 11, 2015
Bash functions to dump or delete events from the LaunchServices QuarantineEvents database
View LSQuarantineEvent.command
#!/bin/bash
DumpQuarantineEventsURLs()
{
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent' | awk '/.+/ {print}' | sort
}
DumpQuarantineEvents()
{
@CocoaBeans
CocoaBeans / .gitattributes
Created Jan 16, 2013
Common .gitattributes for Cocoa development
View .gitattributes
##################################################
## Attribute for diff'ing UTF-8 .strings files
*.strings -crlf set diff
##################################################
## Attribute to for easy merging of Xcode project files
*.pbxproj merge=union
@CocoaBeans
CocoaBeans / config.fish
Last active Dec 11, 2015
Fish shell custom prompt
View config.fish
########################################################################################
### Fish Custom Overrides
### Creates a shell prompt in the form of:
###
### ----------------------------------------------------------------------- 11:56:05
### kevin@kross /S/L/F/C/V/A/F/L/V/A/Support >
########################################################################################
set --global fish_prompt_username_color 555555
@CocoaBeans
CocoaBeans / .gitignore
Created Jan 16, 2013
Common .gitignores for Cocoa development
View .gitignore
*.xcuserdatad/
docset-installed.txt
# OS X Finder
.DS_Store
# Xcode per-user config
*.mode1
*.mode1v3
*.mode2v3