Skip to content

Instantly share code, notes, and snippets.

View TomLiu's full-sized avatar

Liu Yi TomLiu

View GitHub Profile
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
@TomLiu
TomLiu / gist:10436580
Created April 11, 2014 01:43
Macro of text alignment for iOS5 and later
#ifdef NSTextAlignmentCenter
#define BLTextAlignmentCenter NSTextAlignmentCenter
#define BLTextAlignmentLeft NSTextAlignmentLeft
#define BLTextAlignmentRight NSTextAlignmentRight
#define BLTextTruncationTail NSLineBreakByTruncatingTail
#define BLTextTruncationMiddle NSLineBreakByTruncatingMiddle
#else
#define BLTextAlignmentCenter UITextAlignmentCenter
#define BLTextAlignmentLeft UITextAlignmentLeft
#define BLTextAlignmentRight UITextAlignmentRight
@TomLiu
TomLiu / gist:7837127
Created December 7, 2013 04:02
Mac App toggle dock icon
//hide dock icon
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
//show dock icon
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
@TomLiu
TomLiu / NSImage+Blur.h
Last active March 11, 2016 06:40
return a GaussianBlured NSImage
//
// NSImage+Blur.h
// BlurView
//
// Created by 61 on 13-11-19.
// Copyright (c) 2013年 61. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@TomLiu
TomLiu / NSImage+ScreenShot.h
Created November 25, 2013 03:29
Get main screen shot as NSImage
//
// NSImage+ScreenShot.h
// YunPan for Mac
//
// Created by 61 on 13-11-25.
//
//
#import <Cocoa/Cocoa.h>
@TomLiu
TomLiu / gist:7169671
Created October 26, 2013 13:49
change author info for old commits in git
git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "wrong@email.com" ]; then
GIT_AUTHOR_EMAIL=chenyuan.ly@alibaba-inc.com;
GIT_AUTHOR_NAME="chenyuan.ly";
GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all
@TomLiu
TomLiu / CaculateFolderSize.m
Created October 26, 2013 13:28
Caculate a folder size
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:cachePath error:&error];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;
while (fileName = [filesEnumerator nextObject]) {
NSString *filePath = [cachePath stringByAppendingPathComponent:fileName];
NSDictionary *fileDictionary = [fm attributesOfItemAtPath:filePath error:&error];
fileSize += [fileDictionary fileSize];
}
@TomLiu
TomLiu / getBrowserInfo.scpt
Created October 24, 2013 13:50
Get title and url information from Safari & Chrome using Applescript
on GetCurrentApp()
tell application "System Events"
set _app to item 1 of (every process whose frontmost is true)
return name of _app
end tell
end GetCurrentApp
set _app to GetCurrentApp()
@TomLiu
TomLiu / gist:6575851
Created September 16, 2013 01:42
Get the localized name of a display, given the displ
/* Get the localized name of a display, given the display ID. */
-(NSString *)displayNameFromDisplayID:(CGDirectDisplayID)displayID
{
NSString *displayProductName = nil;
/* Get a CFDictionary with a key for the preferred name of the display. */
NSDictionary *displayInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
/* Retrieve the display product name. */
NSDictionary *localizedNames = [displayInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
@TomLiu
TomLiu / DiskInfo.m
Created August 11, 2013 16:41
Get Mac Disk Info
//
// AppDelegate.m
// demo
//
// Created by 61 on 13-8-11.
// Copyright (c) 2013年 61. All rights reserved.
//
#import "AppDelegate.h"
#import <IOKit/IOKitLib.h>