Skip to content

Instantly share code, notes, and snippets.

View isoiphone's full-sized avatar

Jacob Schwartz isoiphone

View GitHub Profile
#include "Config.h"
const Config& Config::get() {
return getWriteable();
}
Config& Config::getWriteable() {
static Config inst;
return inst;
}
@isoiphone
isoiphone / DirtyFlag.hpp
Created June 3, 2013 20:35
An obvious implementation of 'dirty bit' or 'dirty flag' optimization.
class DirtyFlag
{
public:
DirtyFlag() : _dirty(true) {}
void setDirty(bool dirty=true) { _dirty = dirty; }
bool dirty() const { return _dirty; }
private:
bool _dirty;
};
#!/usr/bin/env python
from random import choice
def main():
verbs = open('verbs.txt').read().split()
nouns = open('nouns.txt').read().split()
for i in xrange(100):
print '{0} the {1}'.format(choice(verbs).title(), choice(nouns).title())
if __name__ == "__main__":
#!/usr/bin/env python
from random import choice
def main():
verbs = open('verbs.txt').read().split()
nouns = open('nouns.txt').read().split()
for i in xrange(100):
print '{0} the {1}'.format(choice(verbs).title(), choice(nouns).title())
if __name__ == "__main__":
@isoiphone
isoiphone / gist:5904478
Created July 1, 2013 20:46
Helpful debugging snippet for AFNetworking
#ifdef DEBUG
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSURLRequest* req = [[note object] request];
dbgLog(@"REQUEST: %@ %@", [req HTTPMethod], [req URL]);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidFinishNotification
- (NSString*)getTestString {
NSArray* superlatives = @[@"fabulous", @"excellent", @"cute", @"energetic", @"furry", @"beautiful", @"lovely", @"amazing"];
NSArray* animals = @[@"cats", @"lemurs", @"bears", @"fish", @"sheep", @"sloth",@"aye-ayes", @"platypuses", @"zebras", @"pandas", @"albatross"];
NSUInteger r1 = arc4random()/(float)0x100000000 * [superlatives count];
NSUInteger r2 = arc4random()/(float)0x100000000 * [animals count];
return [NSString stringWithFormat:@"%@ %@", superlatives[r1], animals[r2]];
}
@isoiphone
isoiphone / color.c
Created August 27, 2013 06:48
A useful RGBA 8888 colour class.
// somewhere
const Color4b Color4b::White = Color4b(0xFF,0xFF,0xFF,0xFF);
const Color4b Color4b::Black = Color4b(0x00,0x00,0x00,0xFF);
- (void)notImplemented
{
[self performBlockOnUI:^{
MBProgressHUD* hud = [MBProgressHUD showHUDAddedTo:[self viewForProgressHUD] animated:YES];
hud.labelText = tr(@"Not implemented");
[self performBlockOnUI:^{
[MBProgressHUD hideHUDForView:[self viewForProgressHUD] animated:YES];
} afterDelay:1.5f];
}];
@isoiphone
isoiphone / IsControlCharacterFSM.c
Created December 30, 2013 21:10
Found this old code
#include "IsControlCharacterFSM.h"
// This is a state machine to determine whether or not the passed character is part of a
// TELNET control sequence.
// It must be called for every character read in order to manage state appropriately.
// Credit where credit is due:
// Ryan Rawson (ryan@netidea.com) wrote this for FreeTrade. some time around 2000.
bool IsControlCharacterFSM(char ch)
{
static enum {norm,riac,rddww,rsb,rsiac} state = norm;
@isoiphone
isoiphone / gist:8323683
Created January 8, 2014 20:09
Some functions are like recurring nightmares... I have this vague feeling I've written this many times before.
UIImage* aspectFitImage(UIImage* source, CGSize size)
{
const float wr = source.size.width/size.width;
const float hr = source.size.height/size.height;
const float scale = 1.0f/MIN(wr, hr);
const float width = ceilf(source.size.width*scale);
const float height = ceilf(source.size.height*scale);
CGRect rect = {(size.width-width)*0.5f, (size.height-height)*0.5f, width, height};
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);