Skip to content

Instantly share code, notes, and snippets.

@vitonzhang
vitonzhang / when.swift
Last active February 14, 2017 08:48
Dig into PromiseKit source code.
#if os(Linux)
import Foundation
import Dispatch
#else
import Foundation.NSProgress
#endif
private func _when<T>(_ promises: [Promise<T>]) -> Promise<Void> {
// root为类型PendingTuple的变量。参考Promise.swift中对class func pending()的注解。
// 类型PendingTuple的定义如下:
@vitonzhang
vitonzhang / State.swift
Last active February 10, 2017 08:47
Dig into PromiseKit source code.
import class Dispatch.DispatchQueue
import func Foundation.NSLog
// Seal<T>代表某个Promise<T>的状态:pending, 尚未解决 ; resolved, 已解答/已解决。
enum Seal<T> {
case pending(Handlers<T>)
case resolved(Resolution<T>)
}
// Resolution<T>代表某个Promise<T>的解答结果:fulfilled,已被完成;rejected,被拒绝。
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
@vitonzhang
vitonzhang / route.c
Last active January 16, 2017 04:05
Source code from net/route.h/c
int
rtrequest(req, dst, gateway, netmask, flags, ret_nrt)
int req, flags;
struct sockaddr *dst, *gateway, *netmask;
struct rtentry **ret_nrt;
{
int s = splnet(); int error = 0; // splnet()
register struct rtentry *rt;
register struct radix_node *rn;
register struct radix_node_head *rnh;
/* $NetBSD: mkarp.c,v 1.2.2.1 2000/02/12 16:49:38 he Exp $ */
/*
* Copyright (c) 1984, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Sun Microsystems, Inc.
*
* Redistribution and use in source and binary forms, with or without
@vitonzhang
vitonzhang / arp.c
Last active January 13, 2017 07:20
The source code from bootp.
int
arp_flush(int s, int all, int if_index)
{
char * buf;
char * lim;
int mib[6];
size_t needed;
char * next;
struct rt_msghdr * rtm; // https://www.freebsd.org/cgi/man.cgi?query=route&sektion=4&manpath=NetBSD+7.0
@vitonzhang
vitonzhang / generate_header.py
Created January 12, 2017 09:31
Using the symbols.h and Objective-C symbols from static library to generate the final header file. The final header file is imported in .pch of the project or the workspace.
#! /usr/bin/env python
from __future__ import print_function
import os
import optparse
######
# Delete the macros that is not in SYMBOLS_FILE from HEADER_FILE.
@vitonzhang
vitonzhang / nm_parser.py
Created January 12, 2017 07:28
The parser of the output that is generated by the command 'nm -o -U -p -j libXXX.a'
#! /usr/bin/env python
from __future__ import print_function
import os
import re
import optparse
######
# Parsing the output of nm command(nm -o -U -p -j libXXX.a).
@vitonzhang
vitonzhang / obfuscate_anticheating_app.sh
Last active January 12, 2017 07:26
Shell for Obfuscating the AntiCheating Demo Application.
#!/bin/bash
set -e
# General build options
WORKSPACE=YourApplicationWorkspace.xcworkspace
# PROJECT=YourApplicationProject.xcodeproj
SCHEME=YourApplicationScheme
CONFIGURATION=Release
#SDK=10.0