Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
mwaterfall / gist:953657
Created May 3, 2011 16:24
Runtime iOS Version Checking
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@jsooriah
jsooriah / elasticoverflow.rb
Created May 3, 2011 17:03 — forked from karmi/elasticoverflow.rb
Importing and searching RSS with ElasticSearch and Tire
# =======================================================
# Importing and searching RSS with ElasticSearch and Tire
# =======================================================
#
# This script downloads, parses and indexes Stackoverflow RSS feed with ElasticSearch
# via the [Tire](https://github.com/karmi/tire) Rubygem.
#
# Requirements
# ------------
#
@jsooriah
jsooriah / NSAttributedString+height.h
Created April 18, 2012 13:51
Gives the height an NSAttributedString will take up when constrained to a given width.
#import <CoreText/CoreText.h>
@interface NSAttributedString (Height)
-(CGFloat)boundingHeightForWidth:(CGFloat)inWidth;
@end
@mombrea
mombrea / iOS-UploadImage.h
Created January 17, 2014 01:49
example of a multi-part form post in objective-c
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"REST URL PATH"]];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"unique-consistent-string";
@robmiller
robmiller / gist:ce072c37df914adec0ac
Last active August 29, 2015 14:19
Ruby one-liner to replace URLs in a CSV with their bitly-shortened versions. Assumes you have a bit.ly account
$ gem install bitly
$ export BITLY_USERNAME="your bit.ly username" BITLY_API_KEY="your bit.ly API key"
$ ruby -rcsv -rbitly -e 'b = Bitly.new(ENV["BITLY_USERNAME"], ENV["BITLY_API_KEY"]); CSV.filter { |r| r.each { |f| f.replace b.shorten(f).short_url if f =~ /^https?:/ } }' urls.csv > urls.shortened.csv