Skip to content

Instantly share code, notes, and snippets.

View Quotation's full-sized avatar

Xiaolei Wang Quotation

View GitHub Profile
@Quotation
Quotation / backup_mac_appicons.py
Created April 29, 2021 08:46
Backup macOS application icons (.icns file) to a dir.
#coding=utf-8
import os
import plistlib
import bplist
from datetime import datetime
import shutil
import xml
out_dir = None
@Quotation
Quotation / tower-numbering-bookmark.js
Last active November 24, 2015 05:20
Tower.im 文档编辑自动编号
javascript:(function() {$('<button type="button" class="btn btn-numbering">标题重新编号</button>') .appendTo($('.save-btns-wrap .form-field')) .click(function() {var numbers = [0, 0, 0, 0, 0, 0]; $('H1,H2,H3,H4,H5,H6', $('.simditor-body')).each(function(i, e) {var level = parseInt(e.tagName[1]); numbers[level - 1] += 1; for (var i = level; i < numbers.length; i++) {numbers[i] = 0; } var prefix = numbers.slice(0, level).join('.'); e = $(e); var title = e.text(); if (!title.startsWith(prefix)) {title = title.replace(/^(\d\.)*\d\s?/, ''); e.text(prefix + ' ' + title); } }); }); })()
@Quotation
Quotation / ResizeableTabBarController.m
Created July 17, 2015 06:49
UITabBar height hack
@interface CTResizeableTabBar : UITabBar
// tabbar高度,为0表示采用系统默认高度
- (instancetype)initWithHeight:(CGFloat)tabBarHeight;
@end
@interface CTResizeableTabBar ()
@Quotation
Quotation / shell.py
Last active August 19, 2023 14:23 — forked from defrex/shell.py
Use ptpython for Django shell
from django.core.management.commands.shell import Command as ShellCommand
import os
class Command(ShellCommand):
shells = ShellCommand.shells.append('ptpython')
def ptpython(self):
try:
# old ptpython
@Quotation
Quotation / pyopencc
Created May 8, 2015 05:39
Python调opencc简繁转换
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE
def chs2cht(chs):
return Popen(['opencc'], stdout=PIPE, stdin=PIPE).communicate(chs)[0][:-1]
print chs2cht('简体')
@Quotation
Quotation / fix-xcode-plugins.sh
Last active August 29, 2015 14:18
Fix Xcode plug-ins after Xcode update
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID`
@Quotation
Quotation / weibo_v6_override.css
Last active August 29, 2015 14:07
新浪微博 V6 自定义 CSS
.WB_cardwrap {
margin-bottom: 0;
}
.WB_tab_a {
margin-bottom: 0;
}
.send_weibo {
margin-bottom: 0;
@Quotation
Quotation / iOSFonts.m
Created February 18, 2014 06:02
List iOS system font files
// Here are .plist files defining system fonts.
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *files = [fileMgr contentsOfDirectoryAtPath:@"/System/Library/Fonts/" error:NULL];
NSLog(@"%@", files);
// Choose one .plist file. The filename depends on iOS version.
NSDictionary *fontCache = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/Fonts/CGFontCache@2x.plist"];
NSLog(@"%@", fontCache);
// Copy font files to App directory for free access.
@Quotation
Quotation / NSString+XMLSafe.m
Last active November 10, 2017 10:07
Make an XML-safe NSString. Replace invalid XML characters with space.
@implementation NSString (XMLSafe)
- (NSString *)xmlSafeString {
static NSMutableCharacterSet *invalidSet = nil;
if (!invalidSet) {
// XML Character Range definition (http://www.w3.org/TR/2008/REC-xml-20081126/#charsets)
// Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
invalidSet = [[NSMutableCharacterSet characterSetWithRange:NSMakeRange(0x9, 1)] retain];
[invalidSet addCharactersInRange:NSMakeRange(0xA, 1)];
[invalidSet addCharactersInRange:NSMakeRange(0xD, 1)];