Skip to content

Instantly share code, notes, and snippets.

@yanks
yanks / gist:1003432
Created June 1, 2011 21:58
the weather
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'RMagick'
def retrieve_image(url)
data = open(url).read
data
end
UIImage *oldimage = [UIImage imageNamed:@"bunny.png"];
UIImage *newImage = [UIImage imageWithCGImage:[oldimage CGImage]
scale:[oldimage scale]
orientation:UIImageOrientationDown];
- (UIImage*)upsideDownBunny {
UIImage *img = [UIImage imageNamed:"@bunny.png"];
CGSize imgSize = [img size];
UIGraphicsBeginImageContext(imgSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM(context, M_PI);
CGContextTranslateCTM(context, -imgSize.width, -imgSize.height);
[img drawInRect:CGRectMake(0, 0, imgSize.width, imgSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
- (UIImage*)upsideDownBunny {
__block CGImageRef cgImg;
__block CGSize imgSize;
__block UIImageOrientation orientation;
dispatch_block_t createStartImgBlock = ^(void) {
// UIImages should only be accessed from the main thread
UIImage *img = [UIImage imageNamed:@"bunny.png"];
imgSize = [img size]; // this size will be pre rotated
orientation = [img imageOrientation];
cgImg = CGImageRetain([img CGImage]); // this data is not rotated
NSString* truncateString(NSString* input)
{
NSCountedSet* set = [[NSCountedSet alloc] init];
for( int i = 0; i < [input length]; i++ ){
[set addObject:[NSString stringWithFormat:@"%c", [input characterAtIndex:i]]];
}
NSMutableString* result = [[NSMutableString alloc] init];
for( NSString* key in set ){
[result appendString:key];
if( [set countForObject:key] > 1 ){