Skip to content

Instantly share code, notes, and snippets.

@chen-hongzhi
chen-hongzhi / Set.swift
Last active July 16, 2021 14:21
An implementation of a Set collection in Swift
//
// Set.swift
// Hover
//
// Created by Chen Hongzhi on 7/12/14.
// Copyright (c) 2014 One Artisan. All rights reserved.
//
import Foundation
@chen-hongzhi
chen-hongzhi / gist:6201369
Created August 10, 2013 17:46
Determine if a JSValue is an instance of Array
// Modified from http://code.google.com/p/jsxobjc/source/browse/trunk/source/JSXore/JSXObjCInterpreter.m
@implementation JSValue (CHAdditions)
- (BOOL)ch_isArray
{
static dispatch_once_t onceToken;
static JSStringRef lengthString = NULL;
static JSStringRef arrayString = NULL;
@chen-hongzhi
chen-hongzhi / gist:5735566
Last active December 18, 2015 05:49
Convert wildcard string to regular expression
NSString *CHRegexPatternForWildcardString(NSString *string)
{
if (string.length == 0) {
return string;
}
static dispatch_once_t onceToken;
static NSRegularExpression *asteriskRegex = nil;
static NSRegularExpression *questionmMarkRegex = nil;
@chen-hongzhi
chen-hongzhi / gist:5719035
Last active September 23, 2021 10:39
Add self-signed CA certificate to the system's keychain and make it trusted.
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certData);
status = SecCertificateAddToKeychain(cert, keychain);
if (status == errSecDuplicateItem) {
status = errSecSuccess;
}
if (status == errSecSuccess) {
int allowErr = -2147409654;
SecPolicyRef x509Policy = SecPolicyCreateBasicX509();