Skip to content

Instantly share code, notes, and snippets.

View kyktommy's full-sized avatar
🎯
Focusing

kyktommy kyktommy

🎯
Focusing
View GitHub Profile
@kyktommy
kyktommy / app.coffee
Created February 22, 2014 10:34
Download P&D Images
request = require 'request'
url = require 'url'
fs = require 'fs'
_ = require 'underscore'
base = 'http://www.puzzledragonx.com/en/img/monster/'
seqs = _.range(1000)
imageNames = seqs.map (n) -> "#{n+1}.jpg"
_.each imageNames, (img) ->
@kyktommy
kyktommy / helper.js
Last active December 29, 2015 14:49
cocos2d-html5 point in polygon
var H = Helper = {
pointInPolyon: function (n, vertices, touch) {
var i, j, c = false;
for (i = 0, j = n - 1; i < n; j = i++) {
if (((vertices[i].y > touch.y) != (vertices[j].y > touch.y)) &&
(touch.x < (vertices[j].x - vertices[i].x) * (touch.y - vertices[i].y) / (vertices[j].y - vertices[i].y) + vertices[i].x )) {
c = !c;
}
}
return c;
require 'nokogiri'
require 'open-uri'
class ImageFetcher
EXCLUDES = [
"http://a2.behance.net/img/site/grey.png"
]
def self.get_all_img_src(url)
@kyktommy
kyktommy / itpub_dl.js
Last active February 11, 2016 10:19
itpub file download js bookmarklet
javascript:(function() {
var $ = jQuery,
div = $('<div>').css({'position': 'fixed', 'width': '500px', 'left': '30%', 'top': '10%', 'background': 'red', 'padding': '20px'}),
ul = $('<ol>'),
cancel = $('<a>').addClass('.cancel').attr('href', '#').css({'float': 'right'}).text('X');
cancel.appendTo(div);
div.append(ul);
$('body').append(div);
@kyktommy
kyktommy / delegate.m
Created November 10, 2013 04:49
KVO, Notification, delegate
// mainViewController
@interface MainViewController () <AwesomeViewController>
_awesomeViewController.delegate = self;
- (void)didSelectLabel;
// awesomeViewController
@protocol AwsomeViewControllerDelegate <NSObject>
@kyktommy
kyktommy / block.m
Last active December 27, 2015 20:39
objc block take the responsibility in current scope
typedef NSString* (^ConfigureNameBlock)(NSString *firstName, NSString *lastName);
- (void) runBlock
{
NSString *suffix = @"i am in your back";
NSString *(^configureName)(NSString *, NSString *) = ^(NSString *firstName, NSString *lastName) {
return [NSString stringWithFormat: @"%@, %@, %@", firstName, lastName, suffix];
};
@kyktommy
kyktommy / app.rb
Created November 9, 2013 11:38
Behance Project Images downloader `ruby app.rb http://www.behance.net/gallery/Web-SPIT-Mx/10331815 ~/Desktop`
require 'nokogiri'
require 'open-uri'
class ImageFetcher
EXCLUDES = [
"http://a2.behance.net/img/site/grey.png"
]
def self.get_all_img_src(url)
@kyktommy
kyktommy / write_to_file.m
Created July 22, 2013 16:07
IOS - File write content to file
// Define directory and file path
NSString *documentDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [documentDir stringByAppendingPathComponent:@"file1.txt"];
// Write NSArray to file
NSArray *numbers = @[@12, @124, @214214];
[numbers writeToFile: filePath atomically:YES];
NSError *error;
@kyktommy
kyktommy / get_twitter.m
Created July 22, 2013 09:07
IOS - social framework Get Twitter API
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted) {
ACAccount *account = [[accountStore accountsWithAccountType:twitterAccountType] lastObject];
NSURL *url = [NSURL URLWithString: @"https://api.twitter.com/1.1/followers/list.json"];
id params = @{@"skip_status" : @"1", @"screen_name":@"kyktommy", @"count": @"100"};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params];
request.account = account;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
@kyktommy
kyktommy / get_friend_list.m
Created July 22, 2013 05:34
IOS - Social Framework Get Facebook Friend list
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
id options = @{
ACFacebookAppIdKey: @"403376439767549",
ACFacebookPermissionsKey: @[ @"email", @"read_friendlists"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options
completion:^(BOOL granted, NSError *error) {