Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
cjgiridhar / tornadocrud.py
Created September 10, 2012 17:36
Tornado - CRUD Web Service
import tornado.ioloop
import tornado.web
from datetime import datetime
import urlparse
from bson.json_util import dumps
import pymongo
from pymongo import Connection
class Home(tornado.web.RequestHandler):
@piaoapiao
piaoapiao / gist:3347092
Created August 14, 2012 07:04
select text in UIView
http://stackoverflow.com/questions/7979592/is-it-possible-to-select-the-text-rendered-by-core-text-in-iphone
@wess
wess / gist:3278911
Created August 6, 2012 22:12
Tapping in fucking CoreText
// A small chunk of it.
- (void)tapGestureAction:(UITapGestureRecognizer *)gesture
{
CGPoint location = [gesture locationInView:self];
_linkLocation = location;
location.y += (ARTICLE_BODY_FONT_SIZE / lineHeightFactor);
CFArrayRef lines = CTFrameGetLines(_frame);
@jjgod
jjgod / CTFeature.c
Created July 31, 2012 21:38
Lookup AAT features with Core Text
// CTTest.c
#include <ApplicationServices/ApplicationServices.h>
CFDictionaryRef findFeatureByName(CFArrayRef features, const char *name)
{
CFDictionaryRef feature = NULL;
CFStringRef featureName = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
CFIndex i;
for (i = 0; i < CFArrayGetCount(features); i++) {
@wess
wess / gist:3136429
Created July 18, 2012 14:14
Get a clipping rect for CoreText
static CGRect clipRectToPath(CGRect rect, CGPathRef path)
{
size_t width = floorf(rect.size.width);
size_t height = floorf(rect.size.height);
uint8_t *points = calloc(width * height, sizeof(*points));
CGContextRef bitmapContext = CGBitmapContextCreate(points, width, height, sizeof(*points) * 8, width, NULL, kCGImageAlphaOnly);
BOOL atStart = NO;
NSRange range = NSMakeRange(0, 0);
NSUInteger x = 0;
@jjgod
jjgod / cascadelist.m
Created April 19, 2012 08:32
Use cascade list attribute to customize font fallback in Core Text
#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
if (argc != 2)
return 0;
NSAutoreleasePool *pool = [NSAutoreleasePool new];
CFStringRef name = (CFStringRef) [NSString stringWithUTF8String: argv[1]];
@boredzo
boredzo / gist:1696100
Created January 28, 2012 22:57
Creating font(s) from a URL
//Core Graphics method
CGDataProviderRef provider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontURL);
CGFontRef graphicsFont = CGFontCreateWithDataProvider(provider);
CTFontRef coreTextFont = CTFontCreateWithGraphicsFont(graphicsFont, fontSize, /*matrix*/ NULL, /*attributes*/ NULL);
if (coreTextFont) {
NSFont *font = (__bridge NSFont *)coreTextFont;
[fonts addObject:font];
CFRelease(coreTextFont);
}
CGFontRelease(graphicsFont);
@rudyjahchan
rudyjahchan / AClassACategoryImplementation.h
Created January 23, 2012 02:42
Monkey-Patching iOS with Objective-C Categories Part I: Simple Extensions and Overrides
#import <Foundation/Foundation.h>
@interface AClass (ACategory)
@end
@ianlivingstone
ianlivingstone / ast_test.py
Created July 9, 2011 18:05
Uses Python AST Module to build a dict/list representaiton of only module/function/classes and then pulls keywords from their docstrings
import ast
import sys
import pprint
import re
type_lookup = {
ast.Module: 'Module',
ast.FunctionDef: 'Function',
ast.ClassDef: 'Class'
}
@rsms
rsms / core-text-snippet1.m
Created January 6, 2011 17:16
Some ramblings and cut-outs from wwdc presentation on CoreText
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
CTFontRef font = CTFontCreateWithName(CFSTR("LucidaGrande"), 11.0, NULL);
CFTypeRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
CFDictionaryRef attributes =
CFDictionaryCreate(kCFAllocatorDefault,
(const void**)keys,