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 / 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 / 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 / DeferredCharField.py
Created May 30, 2019 08:29
Model 保存之后第延迟初始化的 CharField 字段实现
class BasicDeferredDefaultAttribute:
"""
实现支持延迟的 deferred_default 方法
在之前的 Video及Post, asset_id 相关的默认属性生成需要用到 pk, pk 是数据库保存之后自动生成的.
本 Descriptor 实现逻辑是相当于修改版本的 DeferredAttribute. 如果有 pk 并且对应的值为空值.则调用对应的函数读取值并设置.
然后再调用 save.
这个方法要求 Model 在 init 中设置对应的值为 models.DEFERRED
@codetalks-new
codetalks-new / main.py
Created January 25, 2017 13:26
微信 Android 自动发红包脚本
# -*- coding: utf-8 -*-
from com.android.monkeyrunner import MonkeyRunner as mr,MonkeyDevice as md
# Imports the monkeyrunner modules used by this program
# usage : $monkeyrunner main.py
# 下面的坐标是针对 1080 x 1920 的设备的 如果是其他分辨率的设备请自行调整
__author__ = 'banxi'
# Connects to the current device, returning a MonkeyDevice object
print("Waiting for connect...")
device = mr.waitForConnection()
@codetalks-new
codetalks-new / p835-image-overlap.go
Created May 13, 2018 03:04
leetcode p835 image overlap go solution
package main
import "fmt"
func overlapCount(img1, img2 [][]int) int {
count := 0
for i := 0; i < len(img1); i++ {
for j := 0; j < len(img1[0]); j++ {
if img1[i][j] == 1 && img2[i][j] == 1 {
@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 / print_class_hierachy.m
Last active March 17, 2016 04:40
Using Objective Runtime API Dump Class hierachy
#import <Foundation/Foundation.h>
@import ObjectiveC;
void print_class_hierachy(Class cls){
printf("%s\n",class_getName(cls));
Class superclass = class_getSuperclass(cls);
int current_level = 0;
while (superclass) {
current_level++;
for (int level = 0; level < current_level;level++) {
@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 / 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 / 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):