Skip to content

Instantly share code, notes, and snippets.

View codetalks-new's full-sized avatar
🏠
Working from home

codetalks codetalks-new

🏠
Working from home
  • China
View GitHub Profile
@codetalks-new
codetalks-new / leetcode_binary_tree_right_side_view_playground.swift
Created June 11, 2015 07:10
LeetCode Binary Tree Right Side View - Swift solution
//: Play Binary Tree in Playground with Swift 2
import Foundation
/*:
## Binary Tree Right Side View
<https://leetcode.com/problems/binary-tree-right-side-view/>
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
@codetalks-new
codetalks-new / IconTextField.swift
Last active August 29, 2015 14:22
TextField 前面带一个 Icon 的Custom View 实现
//
// IconTextField.swift
// ExamTimePickerDemo
//
// Created by Haizhen Lee on 15/5/29.
// Copyright (c) 2015年 banxi1988. All rights reserved.
// 以下用到的一些 AutoLayout的自定义封装方法见
// https://gist.github.com/banxi1988/8b07212cadaddd28384f
import UIKit
//
// GenericDataSource.swift
//
// Created by Haizhen Lee on 15/5/27.
// Copyright (c) 2015年 banxi1988. All rights reserved.
//
import Foundation
class GenericDataSource<T>:SimpleDataSourceBridge{
@codetalks-new
codetalks-new / NumberPickerAdapter.swift
Created June 3, 2015 14:54
封装了 UIPickerViewDataSource, 和 UIPickerViewDelete的逻辑. 简化 80% 的使用场景
//
// NumberPickerAdapter.swift
// Youjia
//
// Created by banxi1988 on 15/4/27.
//
import UIKit
class NumberPickerAdapter:NSObject,UIPickerViewDataSource,UIPickerViewDelegate{
@codetalks-new
codetalks-new / UIView+PinAutoLayout.swift
Last active February 19, 2020 09:58
简单的AutoLayout封装, 简化80% 的AutoLayout 手写代码
//
// UIView+PinAutoLayout.swift
// banxi1988
// @LastModified 2015/06/12
// Created by banxi1988 on 15/5/28.
// Copyright (c) 2015年 banxi1988. All rights reserved.
//
import UIKit
@codetalks-new
codetalks-new / memoize.swift
Created May 7, 2015 00:33
Swift 版本的 memoize 函数
// from WWDC 2014 Session 404
func memoize_v2<T:Hashable,U>(body: ((T) -> U, T) -> U) -> (T) -> U {
var memo = [T:U]()
var result : ((T) -> U)!
result = { x in
if let q = memo[x] { return q }
let r = body(result,x)
memo[x] = r
return r
}
@codetalks-new
codetalks-new / getMd5_2.smali
Created March 3, 2015 04:59
getMd5_2.smali
.method public static getMd5_2(Ljava/lang/String;)Ljava/lang/String;
.locals 7
.param p0, "originStr" # Ljava/lang/String;
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.prologue
.line 485
@codetalks-new
codetalks-new / alipay_red_gift.py
Created February 25, 2015 14:17
Alipay 自动抢红包脚本
# -*- coding: utf-8 -*-
from time import sleep,time
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
print("Waiting for connect...")
device = MonkeyRunner.waitForConnection()
print("Connected")
while True:
@codetalks-new
codetalks-new / AyncUploadSnippet.swift
Created January 15, 2015 12:22
以 Promise,when 的处理逻辑来进行异步上传
func uploadThreadImages(selectedImages:[SelectedImage],
success:(uploadedImages:[String]) -> Void,
error:(resp:UploadImageResponse)-> Void ){
var remindCount = selectedImages.count
var uploadedImages:[String] = []
showProgress(label: "正上传图片")
let uploadOne = { () -> Void in
remindCount--
@codetalks-new
codetalks-new / GradientMaskImageView.swift
Created January 12, 2015 13:00
GradientMaskImageView
class GradientMaskImageView:UIImageView{
let gradientLayer = CAGradientLayer()
override init(image: UIImage!) {
super.init(image: image)
let startColor = UIColor(white: 0, alpha: 0.05)
let midColor = UIColor(white: 0, alpha: 0.3)
let endColor = UIColor(white: 0, alpha: 0.6)
gradientLayer.colors = [ startColor.CGColor, midColor.CGColor, endColor.CGColor ]
gradientLayer.frame = frame
layer.addSublayer(gradientLayer)