Skip to content

Instantly share code, notes, and snippets.

@darcyliu
darcyliu / gist:4499023
Created January 10, 2013 02:55
svn global ignores for xcode
#vim ~/.subversion/config
global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo
*.rej *~ #*# .#* .*.swp .DS_Store *.xcuserdatad
@darcyliu
darcyliu / gist:5496717
Created May 1, 2013 17:20
Core Data Snippets
//1 Creating a New Managed Object Context
//To create a new managed object context, you need a persistent store coordinator.
NSPersistentStoreCoordinator *psc = <#Get the coordinator#>;
NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] init];
[newContext setPersistentStoreCoordinator:psc];
//using the same coordinator as the existing one
NSManagedObjectContext *context = <#Get the context#>;
NSPersistentStoreCoordinator *psc = [context persistentStoreCoordinator];
NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] init];
@darcyliu
darcyliu / start_memcached.sh
Created August 6, 2013 14:43
start/stop memcached
memcached -d -l 127.0.0.1 -p 11211 -m 64
@darcyliu
darcyliu / gist:6326095
Created August 24, 2013 04:38
UIMotionEffect Demo
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = self.view.bounds;
for (NSInteger i=0; i<10; i++) {
CGFloat left = (frame.size.width-100)/2+i%2*10;
CGFloat top = (frame.size.height-100)/2+i%3*10;
@darcyliu
darcyliu / gist:8168894
Last active December 13, 2016 09:40
Simple CoreText with CTFrameDraw
CGContextRef context = UIGraphicsGetCurrentContext();
// Flip the coordinate system
// Make an attributed string
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Hello CoreText!"];
CFAttributedStringRef attributedStringRef = (CFAttributedStringRef)attributedString;
// Simple CoreText with CTFrameDraw
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attributedStringRef);
@darcyliu
darcyliu / gist:8169106
Created December 29, 2013 10:16
Simple CoreText with CTLineDraw and CTRunDraw
CGContextRef context = UIGraphicsGetCurrentContext();
// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
NSDictionary *attrs = @{NSFontAttributeName: [UIFont systemFontOfSize:20],
NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
@darcyliu
darcyliu / gist:8172847
Created December 29, 2013 17:48
Manual Line Breaking
CGContextRef context = UIGraphicsGetCurrentContext();
// // Flip the coordinate system
// CGContextSetTextMatrix(context, CGAffineTransformIdentity);
// CGContextTranslateCTM(context, 0, self.bounds.size.height);
// CGContextScaleCTM(context, 1.0, -1.0);
UIFont *customFont = [UIFont systemFontOfSize:20];
CTFontRef font = CTFontCreateWithName((CFStringRef)customFont.fontName, 20, NULL);
@darcyliu
darcyliu / command.sh
Created June 4, 2014 08:48
Hello World for Swift and C
export PATH="/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift hello.swift
clang world.c -oworld
@darcyliu
darcyliu / DLMultiSelectionControl.h
Last active August 29, 2015 14:05
DLMultiSectionControl
//
// DLMultiSelectionControl.h
// DLMultiSelectionControl
//
// Created by Darcy Liu on 8/31/14.
// Copyright (c) 2014 Close To U. All rights reserved.
//
#import <UIKit/UIKit.h>
@darcyliu
darcyliu / .htaccess
Last active September 2, 2018 16:53
Apache GZIP compression and Expires headers
# BEGIN GZIP
# http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
<IfModule mod_deflate.c>
# Enabling Compression
SetOutputFilter DEFLATE
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css