Skip to content

Instantly share code, notes, and snippets.

View Pretz's full-sized avatar

Alex Pretzlav Pretz

View GitHub Profile
@Pretz
Pretz / dynamicextension.swift
Created September 29, 2015 20:56
Swift Bug w/ Protocol Extensions
protocol SomeValue {
var name: String? { get }
func getName() -> String?
}
extension SomeValue {
var name: String? {
return nil
}
func getName() -> String? {
@Pretz
Pretz / gist:1338731
Created November 4, 2011 05:37
NSURL oddness
(gdb) po [[NSURL alloc] initWithScheme:@"https" host:@"localhost:8000" path:@"/xauth_login/"]
https://localhost:8000/xauth_login///
(gdb) po [NSURL URLWithString:@"https://localhost:8000/xauth_login/"]
https://localhost:8000/xauth_login/
@Pretz
Pretz / gist:1318141
Created October 26, 2011 22:15
JSON Performance on iPhone 3GS iOS 5
2011-10-26 17:11:01.966 JSONPerfTest[195:707] SBJSON-twitter_public.json 19.425
2011-10-26 17:11:09.877 JSONPerfTest[195:707] YAJL-twitter_public.json 7.879
2011-10-26 17:11:20.179 JSONPerfTest[195:707] TouchJSON-twitter_public.json 10.275
2011-10-26 17:11:22.405 JSONPerfTest[195:707] JSONKit-twitter_public.json 2.204
2011-10-26 17:11:25.267 JSONPerfTest[195:707] NextiveJson-twitter_public.json 2.839
2011-10-26 17:11:27.291 JSONPerfTest[195:707] NSJSONSerialization-twitter_public.json 1.990
2011-10-26 17:11:39.849 JSONPerfTest[195:707] SBJSON-lastfm.json 12.504
2011-10-26 17:11:45.418 JSONPerfTest[195:707] YAJL-lastfm.json 5.546
2011-10-26 17:11:59.969 JSONPerfTest[195:707] TouchJSON-lastfm.json 14.524
@Pretz
Pretz / gist:1317874
Created October 26, 2011 21:09
JSON Perf on iPhone 4S
2011-10-26 16:08:32.778 JSONPerfTest[2436:707] SBJSON-twitter_public.json 2.083
2011-10-26 16:08:33.919 JSONPerfTest[2436:707] YAJL-twitter_public.json 1.136
2011-10-26 16:08:36.969 JSONPerfTest[2436:707] TouchJSON-twitter_public.json 3.047
2011-10-26 16:08:37.737 JSONPerfTest[2436:707] JSONKit-twitter_public.json 0.765
2011-10-26 16:08:38.685 JSONPerfTest[2436:707] NextiveJson-twitter_public.json 0.946
2011-10-26 16:08:39.493 JSONPerfTest[2436:707] NSJSONSerialization-twitter_public.json 0.806
2011-10-26 16:08:43.699 JSONPerfTest[2436:707] SBJSON-lastfm.json 4.201
2011-10-26 16:08:45.641 JSONPerfTest[2436:707] YAJL-lastfm.json 1.940
2011-10-26 16:08:50.868 JSONPerfTest[2436:707] TouchJSON-lastfm.json 5.224
@Pretz
Pretz / gist:1317854
Created October 26, 2011 21:06
JSON Perf in Simulator
2011-10-26 16:04:05.344 JSONPerfTest[27924:10103] SBJSON-twitter_public.json 0.371
2011-10-26 16:04:05.605 JSONPerfTest[27924:10103] YAJL-twitter_public.json 0.259
2011-10-26 16:04:06.076 JSONPerfTest[27924:10103] TouchJSON-twitter_public.json 0.470
2011-10-26 16:04:06.190 JSONPerfTest[27924:10103] JSONKit-twitter_public.json 0.113
2011-10-26 16:04:06.327 JSONPerfTest[27924:10103] NextiveJson-twitter_public.json 0.135
2011-10-26 16:04:06.434 JSONPerfTest[27924:10103] NSJSONSerialization-twitter_public.json 0.106
2011-10-26 16:04:07.093 JSONPerfTest[27924:10103] SBJSON-lastfm.json 0.656
2011-10-26 16:04:07.447 JSONPerfTest[27924:10103] YAJL-lastfm.json 0.354
2011-10-26 16:04:08.275 JSONPerfTest[27924:10103] TouchJSON-lastfm.json 0.827
2011-10-26 16:04:08.444 JSONPerfTest[27924:10103] JSONKit-lastfm.json 0.168
@Pretz
Pretz / find-missing.py
Created May 5, 2011 02:36
Find all tracks in an iTunes library xml file that don't exist. Run from your iTunes folder
import re, htmlentitydefs, os.path, urllib
##
# Removes HTML or XML character references and entities from a text string.
# Thank you Fredrik Lundh
# http://effbot.org/zone/re-sub.htm#unescape-html
#
# @param text The HTML (or XML) source text.
# @return The plain text, as a Unicode string, if necessary.
@Pretz
Pretz / read_http.java
Created April 25, 2011 23:01
WTF Java
int contentLength = 0;
if (request.containsHeader("content-length")) {
contentLength = Integer.parseInt(request.getFirstHeader("content-length").getValue());
}
String bodyString = null;
if (contentLength > 0) {
BasicHttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest(request.getRequestLine());
try {
conn.receiveRequestEntity(req);
@Pretz
Pretz / Business.json
Created April 8, 2011 00:23
Parcelgen description for a Yelp API Business
{
"do_json": true,
"package": "com.yelp.parcelgen",
"props": {
"String": [
"id", "name", "imageUrl", "url", "mobileUrl",
"phone", "displayPhone", "ratingImageUrl",
"ratingImageUrlSmall", "snippetText", "snippetImageUrl"
],
"int": ["reviewCount"],
@Pretz
Pretz / get.swift
Created September 24, 2015 18:21
Fetch items from a Swift collection using negative indices
import Swift
extension CollectionType where Index: SignedNumberType, Index == Index.Distance {
func get(var position: Self.Index) -> Self.Generator.Element? {
if position < 0 {
position = self.endIndex.advancedBy(position)
}
return (indices ~= position) ? self[position] : nil
}
@Pretz
Pretz / trac-tickets-to-gh.py
Created September 21, 2010 03:03 — forked from dittos/trac-tickets-to-gh.py
import trac tickets to github from a mysql trac install
import sys; reload(sys); sys.setdefaultencoding('utf-8')
import MySQLdb
import urllib2
import urllib
import simplejson
login = 'your github login'
token = 'your github API key'
repo = 'username/repo'