Skip to content

Instantly share code, notes, and snippets.

View kenshin03's full-sized avatar

Kenny Tang kenshin03

View GitHub Profile
@kenshin03
kenshin03 / gist:1082659
Created July 14, 2011 15:21
scoring doc by readability
double readabilityMean = 0.0;
if (readabilityText != null){
BasicDBObject readabilityScoresObj = new BasicDBObject();
readabilityScoresObj.put("text", readabilityText);
BagOfReadabilityObjects readabilityStats = new Readability(readabilityText).getMetrics();
double normalizedFlesch = (100 - Math.abs(readabilityStats.getFleschReading() - 50))/100;
double normalizedFleschKincaid = (16 - Math.abs(readabilityStats.getFleschReading() - 13))/16;
double normalizedARI = (16 - Math.abs(readabilityStats.getARI() - 13))/16;
double normalizedLiau = (16 - Math.abs(readabilityStats.getColemanLiau() - 13))/16;
@kenshin03
kenshin03 / gist:5088712
Created March 5, 2013 08:02
A bouncy movein effect for image grids that I experimented with. Don't want to lose it. Demo: https://vimeo.com/61078361
- (void)pushInViewsWithBounce {
self.collectionView.hidden = NO;
for (NSInteger i=0; i<100; i++){
UIView * viewToAnimate = [self.view viewWithTag:i];
if ([viewToAnimate isKindOfClass:[AFCollectionViewCell class]]){
viewToAnimate.hidden = YES;
CALayer * layerToMove = viewToAnimate.layer;
//
// RVCollectionViewLayout.m
// RouletteViewDemo
//
// Created by Kenny Tang on 3/16/13.
// Copyright (c) 2013 Kenny Tang. All rights reserved.
//
#import "RVCollectionViewLayout.h"
#import "RVCollectionViewCell.h"
/*
pseudo code:
*/
var singleRotationValue = 360/this.images;
for (var i=0; i<this.images; i++){
var cardElement = document.createElement(‘div’);
var rotation = singleRotationValue*i + 180;
var applyTransform = ‘ rotateZ(‘ + rotation + ‘deg) translateY(‘ + wheelRadius + ‘) translateX(‘ + wheelRadius + ‘)’;
cardElement.style.webkitTransform = applyTransform;
@kenshin03
kenshin03 / gist:5487487
Created April 30, 2013 08:53
Facebook authentication with ACAccountType
NSDictionary * facebookOptions = @{ACFacebookAppIdKey:kPSHFacebookAppID,
ACFacebookPermissionsKey: @[@"email", @"publish_stream", @"read_stream", @"user_photos"],
ACFacebookAudienceKey:ACFacebookAudienceFriends};
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:facebookOptions
completion: ^(BOOL granted, NSError *error) {
NSLog(@"granted: %i", granted);
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
@kenshin03
kenshin03 / gist:5487495
Created April 30, 2013 08:55
Facebook Graph API request with ACAccountStore refer to https://gist.github.com/kenshin03/5487487 for the initAccount part
- (void) likeFeed:(NSString*)graphID {
InitAccountSuccessBlock successBlock = ^{
NSString * likeURLString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/likes", graphID];
NSURL * feedURL = [NSURL URLWithString:likeURLString];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:nil];
NSLog(@"request.URL: %@", request.URL);
request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
@kenshin03
kenshin03 / gist:5487531
Created April 30, 2013 09:04
Magical Records save before refetching data
// save before refreshing data
[[NSManagedObjectContext MR_defaultContext] saveWithOptions:MRSaveSynchronously completion:^(BOOL success, NSError *error) {
NSArray * feedItemsArray = [FeedItem findAllSortedBy:@"createdTime" ascending:NO];
fetchFeedSuccess(feedItemsArray, nil);
}];
@kenshin03
kenshin03 / gist:5487548
Created April 30, 2013 09:08
Home for iOS initial pod file
platform :ios, '6.1'
pod 'MagicalRecord', '~>2.1.0'
pod 'AFNetworking', '~>1.2.0'
@kenshin03
kenshin03 / gist:5494240
Created May 1, 2013 07:58
Ken Burns effect on image view
- (void)animateBackground {
NSInteger randInt = arc4random()%3;
NSInteger translationX = 0;
NSInteger translationY = 0;
NSInteger scaleX = 0;
NSInteger scaleY = 0;
switch (randInt) {
@kenshin03
kenshin03 / gist:5494243
Created May 1, 2013 07:59
stop animated background
- (void)stopAnimateBackground {
self.backgroundImageView.transform = CGAffineTransformIdentity;
[UIView setAnimationsEnabled:YES];
}