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: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 / 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: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 / 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,
/* This is specific fix for a problem with the windows SDK headers when */
/* using MSVC with an x86 compilation target. On x64 the SDK would enable */
/* MSVC's _InterlockedSomething compiler intrinsics and use #define to make */
/* sure those are used instead of InterlockedSomething library calls. On */
/* x32 it doesn't even though MSVC does support many of those intrinsics. */
/* Including this header fixes that. */
#ifndef _MSVC_INTRINSICS_H
#define _MSVC_INTRINSICS_H
@qtxie
qtxie / calculator.red
Created June 19, 2016 01:21 — forked from greggirwin/calculator.red
Red Calculator
Red [
Title: "Calculator"
File: %calculator.r
Version: 0.0.1
;Date: 18-Jun-2016
Author: [
REBOL version ["Jeff Kreis" "Allen Kamp" "Carl Sassenrath"]
Red port "Gregg Irwin"
]
Purpose: "Simple numeric calculator."
Red [
Title: "Sparks demo"
Author: "Qingtian Xie"
File: %sparks.red
Tabs: 4
Needs: View
]
system/view/auto-sync?: no
@qtxie
qtxie / runtime-class.m
Created March 12, 2016 14:20 — forked from mikeash/runtime-class.m
Creating a usable class purely at runtime using the Objective-C runtime APIs.
// clang -fobjc-arc -framework Foundation runtime-class.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age;
@qtxie
qtxie / rs-mac-window.reds
Last active March 1, 2016 08:12
Red/System Mac OSX Window
Red/System [
Title: "Red/System Mac OSX Window"
Author: "Qingtian Xie"
File: %rs-mac-window.reds
Type: 'library
Tabs: 4
Rights: "Copyright (C) 2014 Qingtian Xie. All rights reserved."
Compiling: "rebview.exe -qs red.r -t Darwin rs-mac-window.reds"
Reference: {
https://github.com/CodaFi/C-Macs
@qtxie
qtxie / Run Red.mac
Created November 9, 2014 08:52
Script for running red in EverEdit
Dim strCommand
Dim strFilename
Dim strOutput
Dim strLog
strFilename = App.ActiveDoc.PathName
strLog = strFilename & ".result"
strCommand = "cmd /c E:\red-043.exe {0} > {1} 2>&1"
strCommand = Replace(strCommand, "{0}", strFilename)
strCommand = Replace(strCommand, "{1}", strLog)