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 / demo_set_hash_magic.py
Created September 5, 2013 12:04
Python中Set集合操作中的实现相减操作的demo
#-*- coding:utf-8 -*-
class Address(object):
def __init__(self, name):
self.name = name
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
@codetalks-new
codetalks-new / generate_many_cid.py
Created September 24, 2013 07:46
以多线程及theading.Rlock,或者gevent加线程生成不可得重复的id
__author__ = 'Alec'
import threading
import time
import thread
import gevent
cids = []
@codetalks-new
codetalks-new / int_to_python.py
Last active January 1, 2016 10:19
一个简单的整形验证函数
def is_empty(value):
"""Check whether the given value should be considered "empty"."""
return value is None or value == '' or (
isinstance(value, (list, tuple, dict)) and not value)
def int_to_python(value,min=None,max=None,empty=False,default=0,error=None):
"""
:param value: 待验证的值
:param min: 值的最小取值范围
:param max: 最大取值范围
@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 / CollectionViewCalendar.swift
Last active December 12, 2016 11:01
A Swift implement of objc.io's CollectionView Layout Demo project https://github.com/objcio/issue-3-collection-view-layouts
// Playground - noun: a place where people can play
import UIKit
class SampleCalendarEvent:NSObject{
let title = "Event\(random()%10000)"
let day = random()%7
let startHour = random()%20
let durationInHours = random()%5 + 1
@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{