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
  • Vancouver, BC
  • 04:40 (UTC -08:00)
  • X @hankbao
View GitHub Profile
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",
@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));
//
// 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: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;
@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 / 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 / GCDMulticastDelegate.h
Created May 31, 2015 07:38
GCDMulticastDelegate
#import <Foundation/Foundation.h>
@class GCDMulticastDelegateEnumerator;
/**
* This class provides multicast delegate functionality. That is:
* - it provides a means for managing a list of delegates
* - any method invocations to an instance of this class are automatically forwarded to all delegates
*
* For example:
@hankbao
hankbao / UIDeivce+Processes.m
Created September 18, 2015 14:04
UIDevice Category For Processes
// .h
@interface UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses;
@end
// .m
#import <sys/sysctl.h>
@implementation UIDevice (ProcessesAdditions)
@hankbao
hankbao / Fuckgfw.conf
Created October 12, 2015 13:47 — forked from jason5ng32/surge.conf
Surge Config
[General]
loglevel = notify
bypass-tun = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12,127.0.0.0/24
[Proxy]
// ADD YOUR PROXY HERE, DON'T FORGET TO REMOVE #
# Proxy = http,$IP,$PORT,$USERNAME,$PASSWORD
# Proxy = https,$IP,$PORT,$USERNAME,$PASSWORD
@hankbao
hankbao / sudoku.hs
Created October 30, 2015 19:37 — forked from kristopherjohnson/sudoku.hs
Sudoku solver in Haskell
#!/usr/bin/env runhaskell
-- Note: For a slight improvement in performance, import the non-portable
-- Data.Array.Unboxed module instead of Data.Array, and change the Board
-- type below to use "UArray" instead of "Array".
import Data.Array
-- Solve the example puzzle specified below
-- TODO: read puzzle from input
main = do