Skip to content

Instantly share code, notes, and snippets.

View Donohue's full-sized avatar

Brian Donohue Donohue

View GitHub Profile
@Donohue
Donohue / background_location_updates
Last active December 17, 2015 16:29
Register for background location updates
location_manager = [[CLLocationManager alloc] init];
location_manager.desiredAccuracy = kCLLocationAccuracyBest;
location_manager.delegate = self;
[location_manager startUpdatingLocation];
updating_location = YES;
@Donohue
Donohue / voip_keep_alive_handler
Last active December 17, 2015 16:29
Register for VOIP keep alive handler
BOOL ret = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^(void) {
if (updating_location) {
[location_manager stopUpdatingLocation];
NSLog(@"Keep alive: Stopping location updates");
}
else {
[location_manager startUpdatingLocation];
NSLog(@"Keep alive: Starting location updates");
}
def fragmention(self, bookmark):
# Normalize whitespace and encode text as UTF8
text = ' '.join(self.text.split()).encode('utf-8')
url_parts = urlparse(bookmark.url)
# If the URL has no path (i.e. http://google.com) add a "/" then append fragmention
formatter = '%s/##%s' if not len(url_parts.path) else '%s##%s'
fragmention_url = formatter % (url_parts.geturl(), urllib.quote_plus(text))
@Donohue
Donohue / gist:2aa0e2f31c1155d717fe
Created June 4, 2014 16:56
Scale and rotate image
- (UIImage *)scaleAndRotateImage:(UIImage *)image {
int kMaxResolution = 320; // Or whatever
CGFloat scale = 1.0;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
scale = [[UIScreen mainScreen] scale];
kMaxResolution *= scale;
}
CGImageRef imgRef = image.CGImage;
- (NSURL *)URLFromText:(NSString *)text {
NSArray *components = [text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSURL *ret = nil;
for (NSString *part in components) {
NSURL *urlCheck = [NSURL URLWithString:part];
if (urlCheck &&
([urlCheck.scheme isEqualToString:@"http"] ||
[urlCheck.scheme isEqualToString:@"https"])) {
ret = urlCheck;
break;

Keybase proof

I hereby claim:

  • I am donohue on github.
  • I am bthdonohue (https://keybase.io/bthdonohue) on keybase.
  • I have a public key whose fingerprint is 6782 B8C0 FF5D CE47 80DE 6E44 CF38 6FB3 4639 9BD7

To claim this, I am signing this object:

OperationalError: (OperationalError) (1114, "The table 'bookmarks' is full")
@Donohue
Donohue / set.py
Created December 6, 2018 19:28
Unique set
#!usr/bin/env python
import sys
with open(sys.argv[1]) as f:
unified_set = set([])
for line in f.readlines():
unified_set.add(line.strip())
for item in unified_set:
print item