Skip to content

Instantly share code, notes, and snippets.

View jamesktan's full-sized avatar
🎯
Focusing

James Tan jamesktan

🎯
Focusing
View GitHub Profile
@jamesktan
jamesktan / LogCleansing.py
Last active November 30, 2015 18:24
Script that parses out the Timestamp, URL, and port of an IIS6 Server Log.
import os
directory = "D:\INFOWEBAPPSLOGS\W3SVC1618619580\\"
fileList = os.listdir(directory)
for fname in fileList:
filePath = directory + fname
a = open(filePath)
c = a.readlines()
for line in c:
if ("/secretariat/article.xml.asp") in line:
@jamesktan
jamesktan / GetUniqueCoreDataElements.m
Last active November 30, 2015 18:24
iOS : Core Data - Get Unique Attributes from Core Data
NSManagedObjectContext *context = <#Get the context#>;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"<#Entity name#>" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"<#Attribute name#>"]];
@jamesktan
jamesktan / GetCoreDataByFunction.m
Created December 18, 2014 15:53
iOS : Core Data - Get Core Data Objects by Function
NSManagedObjectContext *context = <#Get the context#>;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"<#Entity name#>" inManagedObjectContext:context];
[request setEntity:entity];
// Specify that the request should return dictionaries.
[request setResultType:NSDictionaryResultType];
// Create an expression for the key path.
@jamesktan
jamesktan / CalculateSurfaceArea.m
Created December 21, 2014 09:25
Calculate Surface Area of Shape
CGPoint points[N];
CGFloat area = 0;
for (int i = 0; i < N; i++) {
area += (points[i].x * points[(i+1) % N].y - points[(i+1) % N].x * points[i].y)/2.0;
}
@jamesktan
jamesktan / Shell Commands ePub
Last active October 21, 2024 19:25
Unzipping & Zipping ePub from Command Line
// To unzip the epub, move the ePub to a folder, cd to it then simply:
unzip MyEbook.epub
// To zip up an epub:
1. zip -X MyNewEbook.epub mimetype
2. zip -rg MyNewEbook.epub META-INF -x \*.DS_Store
3. zip -rg MyNewEbook.epub OEBPS -x \*.DS_Store
Some explanations necessary here. We start each line with two flags:
@jamesktan
jamesktan / Swift - StringWithFormat.swift
Created November 30, 2015 18:23
Extension function for Swift Strings that will accept a NSMutableArray argument
static func withFormat(format: String, list:NSMutableArray) -> String {
if list.count > 0 {
let path = String(format: format, list.firstObject as! String)
list.removeObject(list.firstObject!)
return self.withFormat(path, list: list)
} else {
return format
}
}
@jamesktan
jamesktan / GASnippets.swift
Created November 30, 2015 18:26
Google Analytics Code Snippets for Debugging
GAI.sharedInstance().logger.logLevel = GAILogLevel.None
#if TARGET_IPHONE_SIMULATOR
// [[GAI sharedInstance] setDryRun:YES];
GAI.sharedInstance.setDryRun:true
#endif