Skip to content

Instantly share code, notes, and snippets.

@uchuugaka
uchuugaka / tornadocrud.py
Created March 3, 2017 01:22 — forked from cjgiridhar/tornadocrud.py
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):
@uchuugaka
uchuugaka / ast_test.py
Created June 26, 2016 12:42 — forked from ianlivingstone/ast_test.py
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'
}
// A view that uses Lion's auto layout code to automatically "stack" views horizontally or vertically. It optionally resizes added subviews along the non-aligned axis.
// It resizes itself based on its content.
// ##############################################################
//
// CStackView.h
// SceneKitTest
//
// Created by Jonathan Wight on 2/19/12.
@uchuugaka
uchuugaka / CTFeature.c
Created November 29, 2012 15:39 — forked from jjgod/CTFeature.c
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++) {
@uchuugaka
uchuugaka / gist:4169858
Created November 29, 2012 15:39 — forked from ishikawa/gist:23178
Typesetting a simple paragraph by using Core Text
- (void) drawText: (NSRect) theRect {
const CTFramesetterRef framesetter =
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_text);
// Initialize a rectangular path.
const CGMutablePathRef path = CGPathCreateMutable();
const CGRect rect = CGRectInset(NSRectToCGRect([self bounds]), 5.0, 5.0);
CGPathAddRect(path, NULL, rect);
// Create the frame and draw it into the graphics context
@uchuugaka
uchuugaka / gist:4169859
Created November 29, 2012 15:39 — forked from zsiegel/gist:3939839
Core Text - Line height property inspection
/* Setup our fonts - One system font from Apple and a custom font */
CTFontRef bodyCopyFont = CTFontCreateWithName((__bridge CFStringRef) [Theme fontForBodyOfSize:11].fontName, [Theme fontForBodyOfSize:11].lineHeight, NULL);
CTFontRef systemFont = CTFontCreateWithName((__bridge CFStringRef) [UIFont systemFontOfSize:11].fontName, [UIFont systemFontOfSize:11].lineHeight, NULL);
/* Lets inspect the properties */
NSLog(@"*****************************************************************");
NSLog(@"SYSTEM-FONT LINE HEIGHT PROPERTY %f", [UIFont systemFontOfSize:11].lineHeight);
NSLog(@"SYSTEM-FONT ASCENDER PROPERTY %f", [UIFont systemFontOfSize:11].lineHeight);
NSLog(@"SYSTEM-FONT DESCENDER PROPERTY %f", [UIFont systemFontOfSize:11].lineHeight);
NSLog(@"SYSTEM-FONT LEADING PROPERTY %f", [UIFont systemFontOfSize:11].lineHeight);
@uchuugaka
uchuugaka / gist:4169855
Created November 29, 2012 15:38 — forked from wess/gist:3136429
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;
@uchuugaka
uchuugaka / gist:4169853
Created November 29, 2012 15:37 — forked from wess/gist:3278911
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);