Skip to content

Instantly share code, notes, and snippets.

dduan / gist:2708979
Created May 16, 2012
Convert web pages to PDF using Python + QtWebkit
View gist:2708979
# Authored by as found in the following link:
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4.QtCore import QObject
from PyQt4.QtCore import QUrl
from PyQt4.QtCore import QSizeF
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'))
dduan / PHP's fucked up syntax.php
Created Aug 9, 2012
Nobody in the right mind would ever invent or use this.
View PHP's fucked up syntax.php
// from
// Show all errors.
class beers {
const softdrink = 'rootbeer';
public static $ale = 'ipa';
dduan / app.scss
Created Jan 14, 2013
An app.scss that works with the app generated by Sencha Cmd with Sencha Touch 2.2 alpha. Replace `resources/sass/app.scss` with it to make `compass compile` work.
View app.scss
@import 'sencha-touch/base';
@import 'sencha-touch/base/all';
@import 'sencha-touch/default';
@import 'sencha-touch/default/all';
// You may remove any of the following modules that you
// do not use in order to create a smaller css file.
@import 'sencha-touch/default/panel';
@import 'sencha-touch/default/button';
@import 'sencha-touch/default/sheet';
View Sencha Touch Workflow with GNU Make and Tmux
SASS_PATH = resources/sass
all: sass coffee
develop: watch server
python3 -m http.server
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:

dduan / gist:2ecc257ab908aff24530
Created Jul 7, 2014
Guessing MIME type from a file name in Objective-C on iOS
View gist:2ecc257ab908aff24530
- (NSString *)guessMIMETypeFromFileName: (NSString *)fileName {
// Borrowed from
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileName pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
if (!MIMEType) {
return @"application/octet-stream";
return (__bridge NSString *)(MIMEType);
View gist:6f504875470569fb6059
Verifying myself: My Bitcoin username is +duan.
dduan / NSAttributedString+SimpleHTMLTag.swift
Created Dec 7, 2014
Convert Simple Text With HTML Tags to NSAttributedString
View NSAttributedString+SimpleHTMLTag.swift
extension NSAttributedString {
func replaceHTMLTag(tag: String, withAttributes attributes: [String: AnyObject]) -> NSAttributedString {
let openTag = "<\(tag)>"
let closeTag = "</\(tag)>"
let resultingText: NSMutableAttributedString = self.mutableCopy() as NSMutableAttributedString
while true {
let plainString = resultingText.string as NSString
let openTagRange = plainString.rangeOfString(openTag)
if openTagRange.length == 0 {
You can’t perform that action at this time.