Skip to content

Instantly share code, notes, and snippets.

View kyktommy's full-sized avatar
🎯
Focusing

kyktommy kyktommy

🎯
Focusing
View GitHub Profile
@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) {
@kyktommy
kyktommy / post_facebook.m
Created July 22, 2013 05:03
IOS - Social Framework Post Facebook Feed
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *rexPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[rexPost setInitialText:@"IOS Learning"];
[rexPost addURL:[[NSURL alloc] initWithString:@"http://www.google.com"]];
[self presentViewController:rexPost animated:YES completion: nil];
[rexPost setCompletionHandler: ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
NSLog(@"Post success");
}
}];
@kyktommy
kyktommy / collection.js
Last active December 17, 2015 00:19
demo js
// In app.js line 148
// defined a collection class
var Collection = Appify.Collection = function(protoProps) { ... }
// It has extended Event modules
// It listen add and remove model event
// user can do: add and remove
var products = new Appify.Collection();
var product = new ProductModel({ name: "t-shirt"})
products.add(product); // => length = 1
@kyktommy
kyktommy / event.html
Created May 3, 2013 06:00
Refractor Spaghetti code Pseudocode in JavaScript
<!-- Using handlebar.js syntax -->
<ul id="events">
{{foreach event in events}}
<li>
<h3>{{event.name}}</h3>
<p>{{event.desc}}</p>
</li>
{{/foreach}}
</ul>
var routingTable = {
'/': function() {
redirect_to('products#index')
},
'/products': function() {
action("products#index");
},
'/products/:id': function(id) {
action("products#show", id);
}
<!-- products template -->
<ul data-bind="products">
<li>{{product.name}}</li>
</ul>
<!-- js -->
var products = Product.fetchAll()
product.add(new product({name: 'shoe'})
import java.util.Random;
class Matrix {
public int[][] matrix;
public int m, n;
// Col, n
public Matrix(int m, int n) {
this.matrix = new int[m][n];
require './lzw.rb'
require './run_length.rb'
def source_gen(range)
range.map { ("A".."B").to_a[rand(2)] }.join
end
def entropy(code)
code.split('').group_by(&:upcase)
.collect { |key, val| [key, val.size.to_f / code.size] }
@kyktommy
kyktommy / gen_64_char.rb
Created April 6, 2013 10:04
Randomly generate 64 characters from 'A' to 'H', then save it to "source_?.txt"
PREFIX = "source_"
POSTFIX = ".txt"
LENGTH = 64
RANGE = 'A'..'H'
SIZE = RANGE.to_a.size - 1
FILE_CODE = 'a'..'d'
def gen; 1.upto(LENGTH).map { RANGE.to_a[rand(SIZE)] }.join; end
# Save result to files
@kyktommy
kyktommy / kvo_ops.m
Created April 4, 2013 10:23
KVO Operation
Employee *e1 = [[Employee alloc] init];
e1.salary = @1000;
Employee *e2 = [[Employee alloc] init];
e2.salary = @2000;
Employee *e3 = [[Employee alloc] init];
e3.salary = @3000;
Employee *e4 = [[Employee alloc] init];
e4.salary = @4000;
NSArray *employees = @[e1, e2, e3, e4];