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 / IconLabel.swift
Last active August 29, 2015 14:12
UILabel like androids TextView with drawable Left
import UIKit
class IconLabel:UIView{
var iconPadding: CGFloat = 6 {
didSet{
updateConstraintsIfNeeded()
}
}
var text :String?{
import UIKit
class CircleImageView: UIImageView {
var borderWidth:CGFloat=6.0{
didSet{
updateBorderStyle()
}
}
var borderColor:UIColor=UIColor(white: 160, alpha: 0.5){
@codetalks-new
codetalks-new / CustomUICollectionViewFlowLayout.swift
Created January 9, 2015 15:41
demo for simple Custom UICollectionViewFlowLayout with decoratorView
// Playground - noun: a place where people can play
import UIKit
extension UIColor{
convenience init(hex:Int){
let red = CGFloat((hex >> 16) & 0xff) / 255.0
let green = CGFloat((hex >> 8) & 0xff) / 255.0
let blue = CGFloat( hex & 0xff) / 255.0
self.init(red:red,green:green,blue:blue,alpha:1)
@codetalks-new
codetalks-new / CommentView.swift
Created January 10, 2015 00:19
A Comment View based on UICollectionViewCell
class CommentView:UICollectionViewCell{
let nameView = UILabel()
let textLabel = UILabel()
class var identifier:String{
return "CommentView"
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
@codetalks-new
codetalks-new / SimpleTextCommentView.swift
Created January 10, 2015 07:43
a Simple AttributedString Demo
class TextCommentView:UILabel{
var name :String = ""{
didSet{
updateText()
}
}
var comment:String = ""{
didSet{
updateText()
@codetalks-new
codetalks-new / CommentViewV2.swift
Created January 12, 2015 04:51
Simple CommentView fix use textLabel.intrincContentSize() bug can auto newline
class CommentView:UIControl{
let nameView = UILabel()
let textLabel = UILabel()
let innerSpace:CGFloat = 4
var insets:UIEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8){
didSet{
invalidateIntrinsicContentSize()
}
}
class var identifier:String{
@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)
@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 / 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 / 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