Skip to content

Instantly share code, notes, and snippets.

View hyukhur's full-sized avatar

Hyuk Hur hyukhur

View GitHub Profile
@hyukhur
hyukhur / Array+Extension.swift
Last active October 23, 2017 02:55
Safety Array subscript, And Safety Array for Optional Index
import Foundation
extension Array {
public subscript (safe index: Array.Index) -> Element? {
get {
return indices ~= index ? self[index] : nil
}
set {
guard let element = newValue else { return }
self[index] = element
@hyukhur
hyukhur / backup-homebrew.cmd
Last active December 21, 2017 09:23
backup Homebrew packages
bash backup-homebrew.sh >restore-homebrew.sh && chmod +x restore-homebrew.sh
#!/bin/bash
brew_command=/usr/local/bin/brew
brew_cask_command="$brew_command cask"
echo '#!/bin/bash'
echo ''
echo 'trap ctrl_c INT'
echo 'function ctrl_c() {'
echo 'echo "** Trapped CTRL-C"'
@hyukhur
hyukhur / gist:87eecabbd4c762432d49524c106d29ee
Last active April 15, 2016 04:59
Objective-C super class & Swift subclass with NSCoding
@interface ObjcClass : NSObject <NSCoding>
@property (nonatomic, strong) NSString *name;
@end
@implementation ObjcClass
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:_name forKey:@"name"];
}
- (instancetype)initWithCoder:(NSCoder *)coder
#!/bin/sh
# Create a RAM disk with same perms as mountpoint
# Script based on http://itux.idev.pro/2012/04/iservice-speed-up-your-xcode-%D0%BD%D0%B5%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D1%8B%D0%B5-%D1%81%D0%BF%D0%BE%D1%81%D0%BE%D0%B1%D1%8B/ with some additions
# Usage: sudo ./xcode_ramdisk.sh start
USERNAME=$(logname)
TMP_DIR="/private/tmp"
RUN_DIR="/var/run"
SYS_CACHES_DIR="/Library/Caches"
@hyukhur
hyukhur / arguments passed on launch with '-option' for Push Notification in Simulator
Created November 15, 2013 06:45
아이폰 개발 중 시뮬레이터에 푸시 전달받아 앱 런칭되는 것을 흉내내야하는 경우가 발생하는데 이 때 사용하면 된다. 스키마 설정에 들어가보면 인자값 설정하는 부분이 있고 -option 이라는 값으로 NSPropertyList 값( apn을 통해 앱으로 전달 받는 포맷)을 그대로 전달해주면 된다.
- (BOOL)application:(UIApplication *)aApplication didFinishLaunchingWithOptions:(NSDictionary *)aLaunchOptions
{
/* for Push Notification in Simulator */
#if TARGET_IPHONE_SIMULATOR
NSProcessInfo *sProcessInfo = [NSProcessInfo processInfo];
NSArray *sArguments = [sProcessInfo arguments];
NSUInteger sIndex = [sArguments indexOfObject:@"-option"];
NSString *sPropertyFomatString = [sArguments objectAtIndexOrNil:sIndex+1];
/* format으로 NULL을 전달하면 앱크래시 */
NSPropertyListFormat sPlistFormat;
@hyukhur
hyukhur / gist:4959036
Created February 15, 2013 07:49
NSDictionary(NSArray) to Plist
NSArray *sDirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sPath = [[sDirs objectAtIndex:0] stringByAppendingPathComponent:@"timeZoneMap.plist"];
NSDictionary *sZone = [(id)[NSLocale class] performSelector:@selector(ISOCountryCodesToTimeZoneMap)];
NSData *sTmp = [NSPropertyListSerialization dataWithPropertyList:sZone format:NSPropertyListBinaryFormat_v1_0 options:kCFPropertyListImmutable error:nil];
[sTmp writeToFile:sPath atomically:YES];
@hyukhur
hyukhur / gist:1372429
Created November 17, 2011 05:20
me2scrap
javascript:(function()%7Blocation.href='me2day://create/post?body='+encodeURIComponent('%22'+document.title+'%22:'+location.href)+'&tags=me2scrap&returnURL='+encodeURIComponent(location.href);%7D)();