Skip to content

Instantly share code, notes, and snippets.

@bluebanboom
bluebanboom / gist:2906362
Created June 10, 2012 15:59
Draw with gloss
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(currentContext, [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.35].CGColor);
CGContextAddRect(currentContext, CGRectMake(0, 1, self.frame.size.width, 1));
CGContextFillPath(currentContext);
CGGradientRef glossGradient;
@bluebanboom
bluebanboom / stringFromTimeInterval
Created June 12, 2012 14:54
Create NSString from NSTimeInterval with format HH:MM::SS
- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval
{
NSInteger ti = (NSInteger)interval;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
NSInteger hours = (ti / 3600);
NSString *time = nil;
if (hours > 0) {
time = [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
}
@bluebanboom
bluebanboom / DateFormat.m
Created June 14, 2012 02:12
Example of formatting the date string
//
// Example of formatting the date string
// "Tue, 16 Dec 2008 11:45:13 +0000"
// to
// "16. December 2008"
//
NSString *feedDateString = @"Tue, 16 Dec 2008 11:45:13 +0000";
//
// A formatter to create a date using the RFC2822 date of a RSS feed
@bluebanboom
bluebanboom / md5HexDigest.m
Created June 16, 2012 01:07
md5HexDigest
#import <CommonCrypto/CommonDigest.h>
+ (NSString*)md5HexDigest:(NSString*)input
{
const char* str = [input UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
@bluebanboom
bluebanboom / gist:2987600
Created June 25, 2012 09:21
UIAlertView Code Snippet
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:<#Code#>
message:<#Code#>
delegate:<#Code#>
cancelButtonTitle:@"确定"
otherButtonTitles:<#Code#>];
[alerView show];
[alerView release];
@bluebanboom
bluebanboom / luatableExp.c
Created September 22, 2012 16:45
Example of use lua table in C.
#include <stdio.h>
#include <stdlib.h>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#pragma comment(lib, "liblua.lib")
@bluebanboom
bluebanboom / keyboard.m
Created October 10, 2012 09:45
Keyboard Show/Hidde Event
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
@bluebanboom
bluebanboom / ARCMacros.h
Created October 11, 2012 12:44
ARC Support Without Branching
//
// ARCMacros.h
//
// Created by John Blanco on 1/28/2011.
// Rapture In Venice releases all rights to this code. Feel free use and/or copy it openly and freely!
//
#if !defined(__clang__) || __clang_major__ < 3
#ifndef __bridge
#define __bridge
@bluebanboom
bluebanboom / gist:3873469
Created October 11, 2012 16:08
Change UIWebView User-Agent.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType
{
NSMutableURLRequest *request = (NSMutableURLRequest *)req;
if ([request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
[request setValue:@"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" forHTTPHeaderField:@"User_Agent"];
}
return YES;
}
@bluebanboom
bluebanboom / savedPhotoImage.m
Created November 9, 2012 05:55
Save UIImage to photos album.
- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError:(NSError *)error contextInfo: (void *)contextInfo {
UIAlertView *alert = nil;
if (error == nil) {
alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"图片保存成功!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
}
else {
NSLog(@"%@", [error localizedDescription]);
NSLog(@"info: %@", contextInfo);
alert = [[UIAlertView alloc] initWithTitle:@"错误" message:@"图片保存失败,请重试!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];