This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIImage *oldimage = [UIImage imageNamed:@"bunny.png"]; | |
UIImage *newImage = [UIImage imageWithCGImage:[oldimage CGImage] | |
scale:[oldimage scale] | |
orientation:UIImageOrientationDown]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'RMagick' | |
def retrieve_image(url) | |
data = open(url).read | |
data | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
str = String.new(ARGV[0]) | |
if str.nil? || str.length < 2 then | |
puts "usage: anagram <string>" | |
exit | |
end | |
anagram_set = SortedSet.new | |
(0..str.length-1).each do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiples(num,max) | |
ret_val = [] | |
max.times() do |i| | |
ret_val << i if i%num == 0 | |
end | |
ret_val | |
end | |
require 'set' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prev = 1 | |
current = 1 | |
sum = 0 | |
while( current < 4000000 ) | |
tmp = current | |
current+=prev | |
prev = tmp | |
if current % 2 == 0 then | |
sum += current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime(num) | |
factor = 2 | |
max = num/2 | |
while factor <= max | |
if( num%factor == 0 ) then | |
return false | |
end | |
factor+=1 | |
end | |
return true |
OlderNewer