Skip to content

Instantly share code, notes, and snippets.

View zhangxigithub's full-sized avatar

Sid Zhang zhangxigithub

View GitHub Profile
@zhangxigithub
zhangxigithub / RepeatCodeCount.py
Created February 1, 2018 14:07
RepeatCodeCount
import os
result = {"":0}
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
path = os.path.join(root, name)
ext = os.path.splitext(name)[1]
if ext == ".swift":
f = open(path, "r")
@zhangxigithub
zhangxigithub / capture.swift
Created January 3, 2018 15:24
Swift closure capture or not
var a = 1
var b = 1
//Do not capture
let add1 = {
print(a+b)
}
add1() //2
a = 2
b = 3
@zhangxigithub
zhangxigithub / shell.sh
Created November 27, 2017 08:19
TinyPNG
API_KEY=123456
for f in "$@"
do
JSON=$(curl --user api:$API_KEY --data-binary "@$f" -i https://api.tinify.com/shrink)
RESULT=${JSON##*url\":\"}
RESULT=${RESULT%%\"\}\}}
IMAGE=${f%.*}_tinypng.${f##*.}
curl "$RESULT" -o "$IMAGE"
nodePath="https://nodejs.org/dist/v4.4.7/node-v4.4.7-linux-x86.tar.xz"
tmpPath="tmpnode"
mkdir $tmpPath
cd $tmpPath
wget $nodePath
xz -z *.tar.xz
tar -xvf *.tar
cd "node-v4.4.7-linux-x86"
@zhangxigithub
zhangxigithub / chain.swift
Created September 23, 2014 18:57
Swift_Chain
import UIKit
class Person:NSObject
{
var name:String!
init(name:String){
self.name = name
println("init \(name)")
}
@zhangxigithub
zhangxigithub / UIView+ZXPop.h
Created September 1, 2014 15:24
UIView+ZXPop.h
//
// UIView+ZXPop.h
// sdhgasdgf
//
// Created by 张玺 on 14-9-1.
// Copyright (c) 2014年 zhangxi.me. All rights reserved.
//
#define kZXPopBlurImageTag -5531
#define kZXPopBlurViewTag -5532
#define kZXPopViewTag -5533
@zhangxigithub
zhangxigithub / db2.py
Last active August 29, 2015 14:05
[改进,多线程下载]下载豆瓣妹子的图片 http://dbmeizi.com 使用方法:python db.py 会在当前目录下创建dbmeizi文件夹并下载所有图片
#coding:utf-8
#!/usr/bin/python
import Queue
import threading
import os
import time
import random
import urlparse,urllib,urllib2,os,time,threading,Queue
from bs4 import BeautifulSoup
@zhangxigithub
zhangxigithub / db.py
Last active August 29, 2015 14:05
下载豆瓣妹子的图片 http://dbmeizi.com 使用方法:python db.py 会在当前目录下创建dbmeizi文件夹并下载所有图片
#coding:utf-8
#!/usr/bin/python
import urlparse,urllib,urllib2,os
from bs4 import BeautifulSoup
print "======start======"
print "./dbmeizi"
def downloadImage(imageURL):
url = urlparse.urlparse(imageURL)
@zhangxigithub
zhangxigithub / api.py
Last active August 29, 2015 14:05
change url to apiary.io demo:http://docs.zxtest1.apiary.io
#coding:utf-8
#!/usr/bin/python
import getopt,sys,urlparse,urllib2,json
def getAPI(theURL):
jsonString=urllib2.urlopen(theURL).read()
page = json.dumps(json.loads(jsonString),indent=4)
page = " "+page.replace("\n","\n ")
@zhangxigithub
zhangxigithub / copy.swift
Created July 16, 2014 09:48
swift copy
import Cocoa
class Human:NSCopying
{
var name = ".."
var spouse:Human?
func copy() -> AnyObject! {