Skip to content

Instantly share code, notes, and snippets.

@taberh
taberh / gist:9381697
Created March 6, 2014 03:24
Determine site is open as web app
window.navigator.standalone
@taberh
taberh / gist:7035606
Created October 18, 2013 02:29
批量重命名
for i in `ls`; do mv -f $i `echo $i | sed 's/{match_reg}/{replace_reg}/'`; done
@taberh
taberh / README.md
Last active April 13, 2016 15:10
Convert Data URI to Blob then can append FormData

#Covert Data URI to Blob

@taberh
taberh / iOS-arc-flag
Last active October 13, 2015 05:28
arc or noarc flag
ARC: -fobjc-arc
NO-ARC: -fno-objc-arc
@taberh
taberh / gist:3719322
Created September 14, 2012 01:45
Use Core Graphics draw triangle
void drawTriangle(CGContextRef context, CGPoint startPoint, CGPoint secondPoint, CGPoint lastPoint)
{
CGContextSaveGState(context);
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, secondPoint.x, secondPoint.y);
CGContextAddLineToPoint(context, lastPoint.x, lastPoint.y);
CGContextClosePath(context);
CGContextFillPath(context);
CGContextRestoreGState(context);
@taberh
taberh / gist:3719302
Created September 14, 2012 01:40
Use Core Graphics draw corner
void drawCorner(CGContextRef context, CGRect rect, float corner)
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM(context, corner, corner);
CGFloat fw = CGRectGetWidth(rect) / corner;
CGFloat fh = CGRectGetHeight(rect) / corner;
CGContextMoveToPoint(context, fw, fh/2);
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);
@taberh
taberh / gist:3689377
Created September 10, 2012 07:12
DLog
#ifdef DEBUG
# define DLog(...) NSLog(__VA_ARGS__)
#else
# define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
@taberh
taberh / gist:3607887
Created September 3, 2012 08:30
radians and degrees convert
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180 / M_PI;};
@taberh
taberh / gist:3365672
Created August 16, 2012 02:15
check ios app is first launch
#define LAST_LAUNCH_VERSION_KEY @"last_launch_version_of_application"
- (BOOL)isFirstLoad
{
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastLaunchVersion = [defaults objectForKey:LAST_LAUNCH_VERSION_KEY];
if (!lastLaunchVersion || ![lastLaunchVersion isEqualToString:currentVersion]) {
@taberh
taberh / gist:3357386
Created August 15, 2012 07:32
get app infomation from itunes.apple.com
//HTTP POST - http://itunes.apple.com/lookup?id={appid}
//Result(JSON):
{
"resultCount":1,
"results": [
{
"kind":"software",