Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️

Jon Parise jparise

🛠️
View GitHub Profile
@jparise
jparise / olympics.py
Last active Feb 6, 2022
Olympic Medal Standings for Vestaboard
View olympics.py
#!/usr/bin/env python3
"""Olympic Medal Standings for Vestaboard"""
# pip install beautifulsoup4 vesta
import argparse
import logging
import time
from collections import namedtuple
@jparise
jparise / AFHTTPRequestOperationManager+Retries.h
Created Jun 9, 2016
AFHTTPRequestOperationManager (Retries)
View AFHTTPRequestOperationManager+Retries.h
//
// AFHTTPRequestOperationManager+Retries.h
// Pinterest
//
// Created by Jon Parise on 5/20/13.
// Copyright (c) 2013 Pinterest. All rights reserved.
//
#import "AFHTTPRequestOperationManager.h"
#import "AFHTTPRequestOperation.h"
View keybase.md

Keybase proof

I hereby claim:

  • I am jparise on github.
  • I am jparise (https://keybase.io/jparise) on keybase.
  • I have a public key whose fingerprint is D54B ADE7 F74D C699 6F3B FA58 B2BE C105 157A C76F

To claim this, I am signing this object:

@jparise
jparise / find-unused-images.sh
Created Feb 5, 2013
Find unused images in iOS projects
View find-unused-images.sh
#!/bin/bash
for i in `find . -name "*.png" -o -name "*.jpg"`; do
file=`basename -s .jpg "$i" | xargs basename -s .png | xargs basename -s @2x`
result=`ack -i "$file"`
if [ -z "$result" ]; then
echo "$i"
fi
done
@jparise
jparise / gist:4076671
Created Nov 15, 2012
[NSString -substringMatchingPattern:]
View gist:4076671
- (NSString *)substringMatchingPattern:(NSString *)pattern {
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
if (regex) {
NSAssert1(regex.numberOfCaptureGroups == 1, @"Pattern must include exactly one capture group: %@", pattern);
NSTextCheckingResult *match = [regex firstMatchInString:self options:0 range:NSMakeRange(0, self.length)];
if (match && match.numberOfRanges == 2) {
return [self substringWithRange:[match rangeAtIndex:1]];
}
}
@jparise
jparise / gist:3778366
Created Sep 24, 2012
-arrayByApplyingBlock:
View gist:3778366
- (NSArray *)arrayByApplyingBlock:(id (^)(id obj))block {
NSParameterAssert(block != nil);
NSMutableArray *result = [NSMutableArray arrayWithCapacity:self.count];
for (id obj in self) {
[result addObject:block(obj)];
}
return result;
}
@jparise
jparise / gist:3428652
Created Aug 22, 2012
Tornado Graceful Shutdown
View gist:3428652
def shutdown(graceful=True):
"""Shut down the application.
If a graceful stop is requested, waits for all of the IO loop's
handlers to finish before shutting down the rest of the process.
We impose a 10 second timeout.
"""
ioloop = tornado.ioloop.IOLoop.instance()
def final_stop():
@jparise
jparise / gist:2789026
Created May 25, 2012
Protocol Buffer Mixin for Tornado
View gist:2789026
class ProtocolBufferMixin(object):
"""Protocol Buffer support for RequestHandler objects."""
MIMETYPE = 'application/x-protobuf'
def read_protobuf(self, message_type, data):
"""Attempts to parse a protocol buffer message from the given data."""
# Create the message object and attempt to parse the data into it.
try:
message = message_type()
@jparise
jparise / NSCountedSet+Dictionary.h
Created Jan 31, 2012
NSCountedSet(NSDictionaryExtensions)
View NSCountedSet+Dictionary.h
#import <Foundation/Foundation.h>
@interface NSCountedSet (NSDictionaryExtensions)
- (id)initWithDictionary:(NSDictionary *)dict;
- (void)addObjectsFromDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionary;
@end
@jparise
jparise / gist:1650004
Created Jan 20, 2012
NSStringFromIndexSet()
View gist:1650004
NSString * NSStringFromIndexSet(NSIndexSet *indexSet) {
NSMutableString *string = nil;
NSRange range = NSMakeRange([indexSet firstIndex], 1);
while (range.location != NSNotFound) {
NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location];
while (nextIndex == range.location + range.length) {
range.length++;
nextIndex = [indexSet indexGreaterThanIndex:nextIndex];
}