Skip to content

Instantly share code, notes, and snippets.

func sleep(_ time: Double) {
usleep(UInt32(time * 1000000))
}
func debug(_ strings: Any...) -> some View {
var string = ""
for component in strings {
string += "\(component)" + " "
}
@blladnar
blladnar / stopwatch
Created October 28, 2011 13:58
Stopwatch for timing stuff
#import <mach/mach_time.h>
#define StopWatchStart() uint64_t startTime = mach_absolute_time()
#define StopWatchEnd(caption) uint64_t elapsed = mach_absolute_time() - startTime; static mach_timebase_info_data_t sTimebaseInfo; if ( sTimebaseInfo.denom == 0 ) { (void) mach_timebase_info(&sTimebaseInfo); } uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom / 1000000; DLog(@"%s: %qu ms\n", caption, elapsedNano)
@blladnar
blladnar / castoperator
Created October 28, 2011 12:34
Cast Operator Basics
class A
{
public:
A(int n): m_n(n){}
int GetNumber() const { return m_n; }
operator int() const { return GetNumber(); }
protected:
int m_n;
};
@blladnar
blladnar / FatBinary.sh
Created October 22, 2011 15:00
Build iOS static library for simulator and device
# Version 2.0 (updated for Xcode 4, with some fixes)
# Changes:
# - Works with xcode 4, even when running xcode 3 projects (Workarounds for apple bugs)
# - Faster / better: only runs lipo once, instead of once per recursion
# - Added some debugging statemetns that can be switched on/off by changing the DEBUG_THIS_SCRIPT variable to "true"
# - Fixed some typos
#
# Purpose:
# Create a static library for iPhone from within XCode
# Because Apple staff DELIBERATELY broke Xcode to make this impossible from the GUI (Xcode 3.2.3 specifically states this in the Release notes!)
@blladnar
blladnar / gist:1301940
Created October 20, 2011 18:46
Save To Desktop
BOOL QuickSavePic( Bitmap* pBitmap, const CString& strFilename )
{
CString strExt = strFilename.Mid( strFilename.ReverseFind( NEVER_TRANSLATE('.') ) + 1 );
strExt.MakeUpper();
CString strFormat;
if ( strExt == NEVER_TRANSLATE("JPG") ) strFormat = NEVER_TRANSLATE("image/jpeg");
if ( strExt == NEVER_TRANSLATE("JPEG") ) strFormat = NEVER_TRANSLATE("image/jpeg");
if ( strExt == NEVER_TRANSLATE("GIF") ) strFormat = NEVER_TRANSLATE("image/gif");
if ( strExt == NEVER_TRANSLATE("PNG") ) strFormat = NEVER_TRANSLATE("image/png");