Skip to content

Instantly share code, notes, and snippets.

@foobit
foobit / image to raw
Created April 30, 2012 15:38
UIImage/NSImage to raw buffer
NSString* file = [[NSString alloc] initWithUTF8String:pth.c_str()];
CGImageRef image = [UIImage imageWithContentsOfFile:file].CGImage;
[file release];
m_width = CGImageGetWidth(image);
m_height = CGImageGetHeight(image);
m_poww = std::max<int>(math::high_pow2(m_width), 16);
m_powh = std::max<int>(math::high_pow2(m_height), 16);
int pitch = m_poww * 4;
@foobit
foobit / gist:3783859
Created September 25, 2012 19:17
iOS resign and validate
#!/bin/bash
# apply
codesign -f -s "iPhone Developer" -v MyApp.app
# check it
codesign -d --entitlements - MyApp.app
@foobit
foobit / gist:3840555
Created October 5, 2012 15:34
C++11 mutex, wait_event
#include <future>
class wait_event
{
std::condition_variable cond;
std::mutex m;
public:
void signal()
{
std::lock_guard<std::mutex> lock(m);
@foobit
foobit / gist:4519483
Created January 12, 2013 17:38
multi_function - multicast observer. Based on Generalizing Observer By Herb Sutter http://www.drdobbs.com/cpp/generalizing-observer/184403873
// Dr. Dobb's
// Generalizing Observer By Herb Sutter
// http://www.drdobbs.com/cpp/generalizing-observer/184403873
//
#pragma once
#include <list>
#include <functional>
@foobit
foobit / gist:4618064
Last active December 11, 2015 14:59
64bit (OSX and *nix) vsnprintf trashes va_list args. Must va_start between requesting length and performing expansion
std::string string_format(const char* s, ...)
{
va_list args;
va_start(args, s);
std::string result;
int len = vsnprintf(nullptr, 0, s, args);
if (len > 0)
{
@foobit
foobit / gist:5065376
Created March 1, 2013 15:26
set "git push" to only push current branch
git config --global push.default tracking
@foobit
foobit / gist:5126115
Created March 9, 2013 22:46
Configure p4merge as git's default merge/diff tool
git config --global merge.tool p4merge
git config --global mergetool.p4merge.trustExitCode false
git config --global diff.tool p4merge
@foobit
foobit / gist:5497649
Created May 1, 2013 19:23
MSBuild conditional Assembly Reference
<Reference Include="MonoMac" Condition="'$(Configuration)'=='DebugMono'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Mono|AnyCPU' ">
<DefineConstants>PLATFORM_MONO</DefineConstants>
<PropertyGroup />
@foobit
foobit / find.sh
Created May 17, 2013 19:51
recurse folder find all by optional ext and return only file name
#!/bin/bash
if [-z "$1" ]; then
BASE_PATH=.
else
BASE_PATH=$1
fi
if [-z "$2" ]; then
FILTER_EXT=*
@foobit
foobit / exec.py
Created May 19, 2013 23:46
Enable GUI support for Sublime Text build command
class AsyncProcess(object):
def __init__(self, arg_list, env, listener,
# .... (removed) code
# Hide the console window on Windows
startupinfo = None
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
# comment line below to enable GUI processes