Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View CocoaBeans's full-sized avatar

Kevin Ross CocoaBeans

View GitHub Profile
@CocoaBeans
CocoaBeans / gist:4758423
Created February 11, 2013 23:02
Rebuild the LaunchServices database
#!/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 / gist:5054672
Created February 28, 2013 06:22
List logged in *console* users on MacOS X
#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 / PrintStackTrace.c
Created April 30, 2013 20:27
Print a symbolicated stack trace
#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:6074002
Created July 24, 2013 20:01
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......]
#define $(...) ((NSString *)[NSString stringWithFormat:__VA_ARGS__,nil])
// use like so...[$(@"whatever%ld %@", 2, obj ) stringByRemoving......
@CocoaBeans
CocoaBeans / GetRunningBSDProcesses.m
Created September 8, 2013 18:37
Returns a list of running BSD processes efficiently using sysctl
/* 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 / OOPinC.c
Last active December 23, 2015 22:59
OOP in C Example
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 / StringsLintCheck.sh
Created September 27, 2013 20:46
StringsLintCheck
#!/bin/bash
# for LocalizableStringsIn in $(find "${PROJECT_DIR}"/Languages -name "Localizable.strings.in" -print)
# do
# LocalizableStrings="${LocalizableStringsIn/Localizable.strings.in/Localizable.strings}"
# iconv -f UTF-8 -t UTF-16BE < "${LocalizableStringsIn}" > "${LocalizableStrings}"
# done
# NEEDLE='\( -path "*.lproj/*.strings" \! \( -path "*/build/*" \) \)'
HAYSTACK="${PROJECT_DIR}"
@CocoaBeans
CocoaBeans / .gitignore
Last active December 28, 2015 01:19
Basic .gitignore
# OS X Finder
.DS_Store
# Xcode per-user config
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
@CocoaBeans
CocoaBeans / git-delete-local-tags.sh
Created March 25, 2014 19:48
Delete all locate tags in a git repository and fetch the remote tags
git tag -l | xargs git tag -d
git fetch
@CocoaBeans
CocoaBeans / set_bundle_version.sh
Created April 3, 2014 19:38
This script automatically sets the version and short version string of an Xcode project from the Git repository containing the project. To use this script in Xcode 4, add the contents to a "Run Script" build phase for your application target.
#!/bin/bash -x
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode 4, add the contents to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset