Skip to content

Instantly share code, notes, and snippets.

View majie1993's full-sized avatar

Jeff Ma majie1993

View GitHub Profile
@majie1993
majie1993 / nsscreencast_downloader.rb
Last active August 22, 2020 05:04 — forked from cameroncooke/nsscreencast_downloader.rb
Downloads videos from nsscreencast (requires paid account)
# Using this script downloads ALL the videos in NSScreencast.
# Usage: `EMAIL=your email PASSWORD=your password.`
require 'HTTParty'
require 'Nokogiri'
require 'pry'
require "mechanize"
require "parallel"
class Scraper
{"sig":"c6a6be6eb98d6b29698f316b63fcd77b2d6765cf0cfbf9a78470468071fd323717ae8a98542d9010b1d1d8f7e357ae8266eda3ae3c1d98c772cb74b7b085106f1","msghash":"3ebc75c4f9c26ca6b8a93d90167bc3aee62e5823e7033b307529cd451c8afe4f"}
@majie1993
majie1993 / surge_main.conf
Created December 19, 2015 03:56
Config for surge.app
# This config file was created for myself (@shanskc). You may want to add or remove some rules to make efficient use of the Internet.
# Update: Rules and configuration tuning
# 从243开始Surge 加入了proxy和rule分离的配置Override,此文件为rules main.conf,在你的proxy中你可以引入此conf
# eg: 下面为你的proxy.conf,只需引入此main.conf 即可.
# -----START-----
# #!PROXY-OVERRIDE:main.conf
#
# [Proxy]
# Proxy = custom, ip, port, Methor, password
# -----END-----
float statusBarHeight = MIN([UIApplication sharedApplication].statusBarFrame.size.height, [UIApplication sharedApplication].statusBarFrame.size.width);
+ (TZUser *)userWithUniqueUserId:(NSString *)uniqueUserId inManagedObjectContext:(NSManagedObjectContext *)context
{
TZUser *user = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"TZUser" inManagedObjectContext:context];
request.predicate = [NSPredicate predicateWithFormat:@"objectId = %@", uniqueUserId];
NSError *executeFetchError = nil;
user = [[context executeFetchRequest:request error:&executeFetchError] lastObject];
SEL theSelector = NSSelectorFromString(@"setOrientation:animated:");
NSInvocation *anInvocation = [NSInvocation
invocationWithMethodSignature:
[MPMoviePlayerController instanceMethodSignatureForSelector:theSelector]];
[anInvocation setSelector:theSelector];
[anInvocation setTarget:theMovie];
UIInterfaceOrientation val = UIInterfaceOrientationPortrait;
BOOL anim = NO;
[anInvocation setArgument:&val atIndex:2];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:30];
NSDictionary *userAttributes = @{NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor blackColor]};
NSString *text = @"hello";
...
const CGSize textSize = [text sizeWithAttributes: userAttributes];
@majie1993
majie1993 / NSString_to_NSDate
Last active August 29, 2015 14:12
NSString to NSDate
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString* dateString = @"2015/12/9 00:10:00";
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy/MM/dd hh:mm:ss"];
NSDate* date = [dateFormatter dateFromString:dateString];
NSString * updatedStr = [dateFormatter stringFromDate:date];
NSLog(@"time %@", updatedStr);
}
}
sqlite3_stmt *statement = NULL;
sqlite3_prepare_v2(db, "SELECT strftime('%s', ?);", -1, &statement, NULL);
sqlite3_bind_text(statement, 1, [dateString UTF8String], -1, SQLITE_STATIC);
sqlite3_step(statement);
sqlite3_int64 interval = sqlite3_column_int64(statement, 0);
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
@majie1993
majie1993 / new_gist_file
Created December 26, 2014 04:12
Delete blank cell in the foot of UITableView
- (void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view =[ [UIView alloc]init];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
[tableView setTableHeaderView:view];
}