Skip to content

Instantly share code, notes, and snippets.

from lxml import etree
OSM_API_URL = "http://api.openstreetmap.org/api/0.6/map?bbox=%s"
def get_streets(bbox):
"""
Makes an OSM API request and parses the streets and their waypoints in the
XML response, returns a list
@taylanpince
taylanpince / gist:450551
Created June 23, 2010 21:01
Array.indexOf Support for IE
// Issue: IE doesn't support Array.indexOf (!)
// Solution: Use this
if (!Array.indexOf){
Array.prototype.indexOf = function(obj) {
for (var i = 0; i < this.length; i++) {
if (this[i] == obj) {
return i;
}
}
@taylanpince
taylanpince / PLBlocks and Xcode 4 Workaround
Created March 25, 2011 19:40
These symlinks allow Xcode 4 to work with the PLBlocks installer
cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/
sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/GCC\ 4.2\ \(Plausible\ Blocks\ -\ iPhoneOS\).xcplugin
cd /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/
sudo ln -s /Developer/Library/Xcode/Plug-ins/GCC\ 4.2\ \(Plausible\ Blocks\).xcplugin
@taylanpince
taylanpince / gist:1052154
Created June 28, 2011 20:43
blogTO Best of Title Shortener
NSString *trimmedTitle = [self.entryTitle stringByReplacingOccurrencesOfString:@"The Best"
withString:@""
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [self.entryTitle length])];
trimmedTitle = [trimmedTitle stringByReplacingOccurrencesOfString:@"in Toronto"
withString:@""
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [trimmedTitle length])];
@taylanpince
taylanpince / gist:2304382
Created April 4, 2012 18:14
Exporting raster bitmap from shape file
RASTERIZE_COLOR_FIELD = "__color__"
RASTERIZE_COLOR = (158, 18, 110, 200)
pixel_size = 0.05
# Open the data source
orig_data_source = ogr.Open(args[0])
# Make a copy of the layer's data source because we'll need to
@taylanpince
taylanpince / gist:2405109
Created April 17, 2012 10:25
ZBar Integration
ZBarReaderViewController *controller = [ZBarReaderViewController new];
[controller setReaderDelegate:self];
[controller.scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 80.0)];
UILabel *helpLabel = [[UILabel alloc] initWithFrame:CGRectInset(overlayView.bounds, 15.0, 10.0)];
[helpLabel setFont:[UIFont boldSystemFontOfSize:14.0]];
[helpLabel setTextColor:[UIColor whiteColor]];
@taylanpince
taylanpince / gist:2488911
Created April 25, 2012 10:47
Pull to Refresh
#pragma mark - Scroll View Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[super scrollViewDidScroll:scrollView];
if (_refreshInProgress) return;
if (self.tableView.contentOffset.y > 50.0 && self.tableView.contentOffset.y < 140.0) {
if (self.tableView.contentOffset.y <= 90.0) {
[(RefreshView *)self.tableView.tableHeaderView displayInstructions];
@taylanpince
taylanpince / gist:2575090
Created May 2, 2012 08:31
NSArray reorder
static NSInteger compareListingTypesAccordingToStaticOrder(ListingType *type1, ListingType *type2, void *context) {
static NSArray *orderedTypes = nil;
if (orderedTypes == nil) {
orderedTypes = [[NSArray alloc] initWithObjects:
@"Everything", @"Restaurants", @"Bars",
@"Cafes", @"Bakeries", @"Fashion Stores",
@"Design Stores", @"Bookstores", @"Art Galleries",
@"Fitness Clubs", @"Grocery", @"Hotels", @"Services", nil];
}
@taylanpince
taylanpince / gist:2714573
Created May 16, 2012 22:34
Mark Files in Directory with Do Not Backup Attribute
#include <sys/xattr.h>
- (NSInteger)markFilesInDirectoryAsDoNotBackup:(NSString *)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:path];
NSString *filePath = nil;
NSInteger count = 0;
const char *attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
@taylanpince
taylanpince / s3.py
Created June 27, 2013 13:41
Async Tornado S3 uploader, doesn't block, continues uploading after the request is closed
import hashlib, hmac, mimetypes, os, time
from base64 import b64encode, b64decode
from calendar import timegm
from datetime import datetime
from email.utils import formatdate
from urllib import quote
from tornado.gen import coroutine, Return
from tornado.httpclient import AsyncHTTPClient, HTTPError