Skip to content

Instantly share code, notes, and snippets.

View qtxie's full-sized avatar
🏠
Working from home

Qingtian qtxie

🏠
Working from home
  • FullStack Technologies
View GitHub Profile
@qtxie
qtxie / gist:6d86e8d198d836dd0260eea37564a743
Created August 30, 2016 07:58 — forked from neilinglis/gist:4260598
NSTextAlignment Naming Differences
Am I out of order being annoyed at things like this? The naming has changed subtly, the direction is at the end in UIKit but at the start on AppKit. If I'm writing cross platform code then I need to either use the int values directly, which is bad practice, or use a define.
UIKit:
enum {
NSTextAlignmentLeft = 0,
NSTextAlignmentCenter = 1,
NSTextAlignmentRight = 2,
NSTextAlignmentJustified = 3,
NSTextAlignmentNatural = 4,
@qtxie
qtxie / gist:a16717f74bc2f6c83b9ba922367cddc9
Created August 30, 2016 08:58 — forked from zsiegel/gist:3939819
Core Text - Calculating line height
CGFloat GetLineHeightForFont(CTFontRef iFont)
{
CGFloat lineHeight = 0.0;
check(iFont != NULL);
// Get the ascent from the font, already scaled for the font's size
lineHeight += CTFontGetAscent(iFont);
// Get the descent from the font, already scaled for the font's size
@qtxie
qtxie / AttributedString.m
Created September 1, 2016 07:33 — forked from debuggerman/AttributedString.m
Using attributed string
CFMutableAttributedStringRef attributedString = NULL;
CFRange stringRange = CFRangeMake(0, CFAttributedStringGetLength(attributedString));
//color
CGColorRef stringColor = nil;
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat colorComponents[] = {0.0f, 0.0f, 0.0f, 1.0f};
stringColor = CGColorCreate(rgbColorSpace, colorComponents);
CGColorSpaceRelease(rgbColorSpace);
@qtxie
qtxie / gist:1a9d6ae94129a0fe57b8c9c63a095916
Created September 1, 2016 15:18 — forked from zliuva/gist:1084476
A minimal Mach-o x64 executable for OS X
; A minimal Mach-o x64 executable for OS X (also see below Mountain Lion version)
;
; $ nasm -f bin -o tiny_hello tiny_hello.s
; $ chmod +x tiny_hello
; $ ./tiny_hello
; Hello World!
; $
; c.f.
; http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/ ( the original tiny mach-o executable )
@qtxie
qtxie / systemversion.c
Created September 16, 2016 11:41 — forked from deltheil/systemversion.c
iOS: get device OS version from C code via the Objective-C Runtime
#include <objc/runtime.h>
#include <objc/message.h>
#include <CoreFoundation/CoreFoundation.h>
/* ... */
/**
* Return a character string that holds the current version
* of the operating system which is equivalent to:
@qtxie
qtxie / gameoflife2.red
Last active September 30, 2016 07:35 — forked from Mufferaw/gameoflife2.red
system/view/auto-sync?: no
grid: collect [repeat i 50 [keep/only collect [repeat j 50 [keep random true]]]]
scratchgrid: collect [repeat i 50 [keep/only collect [repeat j 50 [keep false]]]]
a: copy grid/1
b: copy grid/50
c: collect [keep/only b keep grid keep/only a]
count-neighbors: function [gridd x y][
@qtxie
qtxie / JSON.red
Last active October 6, 2016 22:39 — forked from dockimbel/JSON.red
JSON toy parser for Red
Red [
Title: "JSON parser"
File: %json.red
Author: "Nenad Rakocevic, Qingtian Xie"
License: "BSD-3 - https://github.com/red/red/blob/master/BSD-3-License.txt"
]
json: context [
quoted-char: charset {"\/bfnrt}
exponent: charset "eE"
@qtxie
qtxie / latency.markdown
Created October 8, 2016 23:15 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@qtxie
qtxie / irq_balance_habrahabr.sh
Created October 24, 2016 04:18 — forked from pavel-odintsov/irq_balance_habrahabr.sh
irq_balance_habrahabr.sh
#!/bin/bash
# from http://habrahabr.ru/post/108240/
ncpus=`grep -ciw ^processor /proc/cpuinfo`
test "$ncpus" -gt 1 || exit 1
n=0
for irq in `cat /proc/interrupts | grep eth | awk '{print $1}' | sed s/\://g`
do
f="/proc/irq/$irq/smp_affinity"
@qtxie
qtxie / gist:67b382155c516b6af7b61a985880380e
Created November 10, 2016 23:30 — forked from Koze/gist:10550725
List of monospace font
// UIFontDescriptor on iOS 7 or later
NSDictionary *traitsAttributes = @{UIFontSymbolicTrait: @(UIFontDescriptorTraitMonoSpace)};
NSDictionary *fontAttributes = @{UIFontDescriptorTraitsAttribute: traitsAttributes};
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:fontAttributes];
NSArray *array = [fontDescriptor matchingFontDescriptorsWithMandatoryKeys:nil];
for (UIFontDescriptor *descriptor in array) {
NSLog(@"%@", descriptor.postscriptName);
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorNameAttribute]);
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorVisibleNameAttribute]);