Skip to content

Instantly share code, notes, and snippets.

View hanksudo's full-sized avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
View GitHub Profile
@hanksudo
hanksudo / JavaScript.sublime-build
Created March 21, 2013 20:27
Build NodeJS script on Sublime Text 2
{
"cmd": ["node", "$file"],
"selector": "source.js",
"path": "/usr/local/bin"
}
@hanksudo
hanksudo / GetWeekDay.m
Created March 26, 2013 07:58
Get day of week.
NSCalendar* cal = [NSCalendar currentCalendar];
NSDateComponents* comp = [cal components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
return [comp weekday]; // 1 = Sunday, 2 = Monday, etc.
@hanksudo
hanksudo / cron jobs
Created April 2, 2013 00:50
Crontab job practices
PATH=/usr/local/bin:/usr/bin
# MAILTO=hank
# min hour day month weekday command
# * * * * * *
*/1 * * * * script.sh # 每一分鐘
10 10 * * * script.sh # 每天早上 10:10
10 10 1 * * script.sh # 每個月第一天的 10:10
30 9 * * 1-5 script.sh # 週一到週五 09:30
0 12 * * sub script.sh # 週日 12:00
@hanksudo
hanksudo / Make-Blogger-Archive-Page.js
Created April 2, 2013 01:40
Make Archive Page by title in Blogger
// from : https://github.com/jhwilson/Create-a-Blogger-archive-page
/* Usage:
<script type="text/javascript" src="http://cloud.github.com/downloads/jhwilson/Create-a-Blogger-archive-page/Make-Blogger-Archive-Page.js"></script>
<script src="http://myblogid.blogspot.tw/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=LoadTheArchive"> </script>
*/
function LoadTheArchive(TotalFeed)
{
var PostTitles = new Array();
var PostURLs = new Array();
@hanksudo
hanksudo / GCD.c
Created April 14, 2013 08:30
Greatest Common Divisor 最大公因數
#include <stdio.h>
int GCD(int, int);
void main(void) {
printf("%d\n",GCD(99, 55));
system("pause");
}
int GCD(int x, int y) {
@hanksudo
hanksudo / AdjustVirtualBoxDiskSize
Created April 19, 2013 09:45
Adjust VirtualBox disk size
VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB
@hanksudo
hanksudo / LocalNotification.m
Created April 25, 2013 06:15
iOS: Local Notification at particular time
//
// AppDelegate.m
//
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSDate *alertTime = [[NSDate date]
dateByAddingTimeInterval:10];
NSDate *alertTime2 = [[NSDate date]
dateByAddingTimeInterval:30];
@hanksudo
hanksudo / CancelOneParticularLocalNotification.m
Created April 25, 2013 06:53
iOS: Cancel one particular LocalNotification
UIApplication *app = [UIApplication sharedApplication];
NSArray *events = [app scheduledLocalNotifications];
cancelNid = @"1";
for (int i=0; i<[events count]; i++)
{
UILocalNotification* notify = [eventArray objectAtIndex:i];
NSString *uid = [NSString stringWithFormat:@"%@",[notify.userInfo valueForKey:@"nid"]];
if ([nid isEqualToString:cancelNid])
@hanksudo
hanksudo / LoopPerformance.js
Created April 25, 2013 18:32
Loop Performance - Cache Array Length, Reference : http://taitems.github.io/Front-End-Development-Guidelines/
var toLoop = new Array(1000);
for (var i = 0; i < toLoop.length; i++) {
// BAD - the length has to be evaluated 1000 times
}
for (var i = 0, len = toLoop.length; i < len; i++) {
// GOOD - the length is only looked up once and then cached
}
@hanksudo
hanksudo / debug_snippet.js
Created April 25, 2013 19:24
debug: show output in a new window
var d=window.open().document;
d.write("<html><body><h1>Hi!</h1> Test!</body></html>");
d.close();