Skip to content

Instantly share code, notes, and snippets.

View hankbao's full-sized avatar
🧠
use it or lose it

Hank Bao hankbao

🧠
use it or lose it
View GitHub Profile
@hankbao
hankbao / ClosureStackOverflow.swift
Created May 13, 2015 04:27
call() and get a stack overflow
import Swift
class ClosureStackOverflow {
private var b: Bool = false
private func callClosure1(callback: Void -> Void) {
println("in closure 1")
callback()
}
private func callClosure2(callback: Void -> Void) {
@hankbao
hankbao / reset_nic.sh
Created April 11, 2013 14:48
Reset network interfaces on OS X
#!/bin/sh
sudo ifconfig en0 down
sudo ifconfig en1 down
sudo route -n flush
sudo ifconfig en0 up
sudo ifconfig en1 up
@hankbao
hankbao / gist:5194309
Created March 19, 2013 07:24
Chop a rectangle from another rectangle on iOS
static
void divide_rect_from_rects(CGRect rect1, CGRect rect2, CGRect *slice, CGRect *remainder, CGRectEdge edge)
{
NSCParameterAssert(slice);
NSCParameterAssert(remainder);
CGRect intersected = CGRectIntersection(rect1, rect2);
if (CGRectIsEmpty(intersected)) {
*slice = CGRectNull;
return;
//
// RVNReceiptValidation.m
//
// Created by Satoshi Numata on 12/06/30.
// Copyright (c) 2012 Sazameki and Satoshi Numata, Ph.D. All rights reserved.
//
// This sample shows how to write the Mac App Store receipt validation code.
// Replace kRVNBundleID and kRVNBundleVersion with your own ones.
//
// This sample is provided because the coding sample found in "Validating Mac App Store Receipts"
@hankbao
hankbao / gist:4378943
Created December 26, 2012 08:46
Get a CGAffineTransform from a UIInterfaceOrientation
#define DEGREES_TO_RADIANS(degrees) (degrees * M_PI / 180)
static CGAffineTransform transformForOrientation(UIInterfaceOrientation orientation)
{
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
case UIInterfaceOrientationLandscapeRight:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-90));
if (typeof (AC) === "undefined") {
AC = {}
}
AC.ImageReplacer = Class.create({
_defaultOptions: {
listenToSwapView: true,
filenameRegex: /(.*)(\.[a-z]{3}($|#.*|\?.*))/i,
filenameInsert: "_☃x",
ignoreCheck: /(^http:\/\/movies\.apple\.com\/|\/105\/|\/global\/elements\/quicktime\/|_(([2-9]|[1-9][0-9]+)x|nohires)(\.[a-z]{3})($|#.*|\?.*))/i,
attribute: "data-hires",