Skip to content

Instantly share code, notes, and snippets.

View takuma104's full-sized avatar

Takuma Mori takuma104

  • Tokyo
View GitHub Profile
# subview walker for iphone-rubycocoa
def walk(v, g)
g[:subviews] = v.subviews.to_a.map {|sv| walk(sv, geom(sv))}
g
end
def geom(v)
{:name=>v.to_s, :subviews=>[], :frame=>v.frame.to_a}
end
// NSDate#descriptionWithTwitterStyle
@interface NSDate(TwitterStyle)
- (NSString*)descriptionWithTwitterStyle;
@end
@implementation NSDate(TwitterStyle)
- (NSString*)descriptionWithTwitterStyle {
time_t now = [[NSDate date] timeIntervalSince1970];
time_t t = [self timeIntervalSince1970];
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
// CGFontRef font = CGFontCreateWithFontName((CFStringRef)[[self font] fontName]);
CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"HiraKakuProN-W3");
// CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"Helvetica");
CGContextSetFont(ctx, font);
CGContextSetFontSize(ctx, 14);
// Transform text characters to unicode glyphs.
MPMusicPlayerController *mpc = [MPMusicPlayerController iPodMusicPlayer];
MPMediaItem *item = [mpc nowPlayingItem];
NSString *tw = [NSString stringWithFormat:@"Now Playing: %@ - %@ - %@",
[item valueForProperty:MPMediaItemPropertyTitle],
[item valueForProperty:MPMediaItemPropertyAlbumTitle],
[item valueForProperty:MPMediaItemPropertyArtist]];
NSLog("%@", tw);
+ (UIImage*)resizedImage:(UIImage*)image withSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
// CGContextSetInterpolationQuality(context, kCGInterpolationLow);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" CONTENT="0.1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE></TITLE>
</HEAD>
>> Hoge = "Hage"
=> "Hage"
>> Hoge + "atama"
=> "Hageatama"
>> HA = Hoge + "atama"
=> "Hageatama"
>> HA
=> "Hageatama"
>>
@takuma104
takuma104 / nestnestnest.m
Created October 23, 2009 13:33
nestnestnest.m
[[[NSURLConnection alloc] initWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:
[NSString stringWithFormat:@"%@/statuses/home_timeline.json", API_URL]]]] autorelease];
@interface UIImage(ImmediateLoad)
+ (UIImage*)imageImmediateLoadWithContentsOfFile:(NSString*)path;
@end
@implementation UIImage(ImmediateLoad)
+ (UIImage*)imageImmediateLoadWithContentsOfFile:(NSString*)path {
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
/*
NSData+XMLParser
Simple XML Parser for iPhone
Usage:
* -I /usr/include/libxml2
* -L libxml2