Skip to content

Instantly share code, notes, and snippets.

dduan / UIColor+IntegerValue.h
Last active Aug 29, 2015
A category that converts UIColor to int32_t for convenient persistence.
View UIColor+IntegerValue.h
// UIColor+SingleValue.h
// Created by Daniel Duan on 1/26/14.
// BSD License
#import <UIKit/UIKit.h>
@interface UIColor (SingleValue)
- (UIColor *)initWithInteger: (int32_t)integer;

Keybase proof

I hereby claim:

  • I am dduan on github.
  • I am duan ( on keybase.
  • I have a public key whose fingerprint is 2D75 873D D420 18FB 5B6B 72C5 4876 9046 F6CC 539C

To claim this, I am signing this object:

View gist:6f504875470569fb6059
Verifying myself: My Bitcoin username is +duan.
dduan / DeselectableSegmentedControl.swift
Created Dec 10, 2014
A Deselectable UISegmentedControl
View DeselectableSegmentedControl.swift
import UIKit
class DeselectableSegmentedControl: UISegmentedControl {
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
let previouslySelectedIndex = self.selectedSegmentIndex
super.touchesEnded(touches, withEvent: event)
if previouslySelectedIndex == self.selectedSegmentIndex {
self.selectedSegmentIndex = UISegmentedControlNoSegment
dduan / BorderedButton.swift
Last active Aug 29, 2015
UIButton with border.
View BorderedButton.swift
// BorderedButton.swift
// Created by Daniel Duan on 12/13/14.
import UIKit
class BorderedButton: UIButton {
override func willMoveToSuperview(newSuperview: UIView?) {
View Complex.swift
struct Complex<T: FloatLiteralConvertible> {
var real: T
var imaginary: T
func +(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
return Complex<Double>(real: lhs.real + rhs.real, imaginary: lhs.imaginary + rhs.imaginary)
func -(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
dduan / QuickOutline.swift
Last active Aug 29, 2015
This script takes a JSON text file with content in {"string:["a","b",…]} format and generates Quick/BDD style test outlines.
View QuickOutline.swift
#!/usr/bin/env xcrun swift
1. chmod +x QuickOutline.swift
2. ./QuickOutline.swift outline.json
this will generate BDD/[Quick]( style test outlines according to outline.json
an example outline.json:
dduan / ChaingPuzzleWithSwift2b2.swift
Last active Aug 29, 2015
Is there a better way to linearize the following construct?
View ChaingPuzzleWithSwift2b2.swift
// Swift 2 Beta 2 to the rescue!
protocol A {
var b: B { get set }
protocol B {
func handle()
extension B {
dduan / Makefile
Last active Aug 29, 2015
Unix 'cat' Command Implemented In Swift Without Foundation
View Makefile
SDKPATH = $(shell xcrun --show-sdk-path --sdk macosx)
TARGETS := cat
all: $(TARGETS)
swiftc -sdk $(SDKPATH) $@.swift -import-objc-header $(CBRIDGEHEADER) -o $@
dduan /
Created Jun 28, 2012
Discover and run all tests in a Python project.
''' Runs tests defined in package 'tests' '''
from unittest import defaultTestLoader, TextTestRunner
TextTestRunner().run('tests', pattern='*.py'))
You can’t perform that action at this time.