Skip to content

Instantly share code, notes, and snippets.

View zwang's full-sized avatar
😀
Plato App

Zhao Wang zwang

😀
Plato App
View GitHub Profile
@zwang
zwang / StringSize.swift
Created November 6, 2016 16:50 — forked from plumhead/StringSize.swift
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
When you get an error code in with the domain kCFStreamErrorDomainSSL, you can generally find the error codes in SecureTransport.h which is in /System/Library/Frameworks/Security.framework. Here are the error codes:
enum {
errSSLProtocol = -9800, /* SSL protocol error */
errSSLNegotiation = -9801, /* Cipher Suite negotiation failure */
errSSLFatalAlert = -9802, /* Fatal alert */
errSSLWouldBlock = -9803, /* I/O would block (not fatal) */
errSSLSessionNotFound = -9804, /* attempt to restore an unknown session */
errSSLClosedGraceful = -9805, /* connection closed gracefully */
errSSLClosedAbort = -9806, /* connection closed via error */
@zwang
zwang / introrx.md
Created April 4, 2017 17:21 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@zwang
zwang / build_gmp.sh
Created July 30, 2017 18:50 — forked from sakrist/build_gmp.sh
GMP and MPFR compile for iOS
#!/bin/bash
set -x
CURRENT=`pwd`
__pr="--print-path"
__name="xcode-select"
DEVELOPER=`${__name} ${__pr}`
GMP_VERSION="5.1.3"
{"sig":"e3acfb82ecda1d700a645ddcf4ae78d9ea45e73c8f069deb9f723602f259b06cc85efe766404cd9912b35330361df628e149dd749c4fda00bcc76fd577d9dddc0","msghash":"083e69c2b4cec2e0aae0d350bdb92b61de1f7d120e1152c9d20a0e8546389c2c"}
@zwang
zwang / v8PromiseDemo.cpp
Created December 20, 2019 19:02 — forked from jupp0r/Demo.cpp
C++ function returning an ES6 promise
#include <node.h>
#include "Test.h"
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;