Skip to content

Instantly share code, notes, and snippets.

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 ){
- (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:@&quot;bunny.png&quot;];
imgSize = [img size]; // this size will be pre rotated
orientation = [img imageOrientation];
cgImg = CGImageRetain([img CGImage]); // this data is not rotated
- (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 *oldimage = [UIImage imageNamed:@"bunny.png"];
UIImage *newImage = [UIImage imageWithCGImage:[oldimage CGImage]
scale:[oldimage scale]
orientation:UIImageOrientationDown];
@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
@yanks
yanks / gist:1003937
Created June 2, 2011 04:33
finding anagrams
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
@yanks
yanks / share_with_jungle_disk.rb
Created January 5, 2012 17:58
Share with Jungle Disk
#!/usr/bin/ruby
require 'base64'
require 'uri'
ARGV.each() do |arg|
#expand
arg = File.expand_path(arg)
pathout = Base64.encode64(arg)
url = "http://localhost:2667/~publish?paths=" + URI.escape(pathout)
puts url
def multiples(num,max)
ret_val = []
max.times() do |i|
ret_val << i if i%num == 0
end
ret_val
end
require 'set'
prev = 1
current = 1
sum = 0
while( current < 4000000 )
tmp = current
current+=prev
prev = tmp
if current % 2 == 0 then
sum += current
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