Skip to content

Instantly share code, notes, and snippets.

View yeonsh's full-sized avatar

Seunghoon Yeon yeonsh

View GitHub Profile
@SuppressLint("NewApi")
@SuppressWarnings("unchecked")
public static void executeTaskInParallel(@SuppressWarnings("rawtypes") AsyncTask task, Bundle params) {
if (MyUtil.hasHoneycomb()) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
} else {
task.execute(params);
}
}
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
/**
* Use this class when you provide logics for background execution.
*
* Implement your code in onAsyncTaskExecute().
*
* If you have to reuse your code, define a dedicated task class using BDAsyncTaskSkeleton class.
@yeonsh
yeonsh / gist:9407615
Created March 7, 2014 08:29
Date string to timestamp
import time
import datetime
date_string = '2013-03-07'
date = datetime.datetime.strptime(date_string, '%Y-%m-%d')
time.mktime(date.timetuple())
==> 1362582000.0
import os
import tldextract
from tld import get_tld
from tld.utils import update_tld_names
TEST_COUNT = 1000000
start_time = os.times()[4]
for i in range(TEST_COUNT):
e = tldextract.extract('http://forums.news.cnn.com:8080/a/b/c/')
sudo pip install virtualenv-clone --upgrade
@yeonsh
yeonsh / gist:6833951
Created October 4, 2013 22:32
OS X Mavericks GM Seed로 업데이트한 후
stevedore.extension Could not load 'user_scripts': virtualenv-clone
stevedore.extension virtualenv-clone
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/stevedore/extension.py", line 89, in _load_plugins
invoke_kwds,
File "/usr/local/lib/python2.7/site-packages/stevedore/extension.py", line 101, in _load_one_plugin
plugin = ep.load()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.40-py2.7.egg/pkg_resources.py", line 2030, in load
if require: self.require(env, installer)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.40-py2.7.egg/pkg_resources.py", line 2043, in require
@yeonsh
yeonsh / gist:5791444
Last active December 18, 2015 13:39
Find file path of system font on OS X
...
NSLog(@"%@", [self getSystemFontPath:18]);
NSLog(@"%s", [self getSystemFontPathCString:18]);
...
- (const char *)getSystemFontPathCString:(CGFloat)argFontSize
{
NSString *path = [self getSystemFontPath:argFontSize];
const char *path_cstring = [path cStringUsingEncoding:[NSString defaultCStringEncoding]];
return path_cstring;
@yeonsh
yeonsh / listdir.py
Created January 25, 2013 04:48
List directories only under given directory
import os
dir = []
def listDirectory(directory):
for f in os.listdir(directory):
path0 = os.path.join(directory, f)
if os.path.isdir(path0):
dir.append(path0)
listDirectory(path0)
@yeonsh
yeonsh / gist:962129
Created May 9, 2011 06:09
Change UINavigationBar Button Color
for (UIView *view in self.navigationController.navigationBar.subviews) {
NSLog(@"%@", [[view class] description]);
LOG_EXPR([[view class] description]);
if ([[[view class] description] isEqualToString:@"UINavigationButton"]) {
[(UINavigationButton *)view setTintColor:[UIColor brownColor]];
}
}
@yeonsh
yeonsh / clearNSURLConnectionCache
Created April 10, 2011 11:29
NSURLConnection의 Cache 삭제
-(void) clearNSURLConnectionCache
{
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
}