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 / 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 / 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 / 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 / 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 / hello_world.asm
Created August 17, 2015 07:21
HelloAssembley OS X from https://lord.io/blog/2014/assembly-on-osx/ with a small bug fix
%define SYSCALL_WRITE 0x2000004
%define SYSCALL_EXIT 0x2000001
global start
start:
mov rdi, 1
;mov rsi, str
lea rsi, [rel str]
mov rdx, strlen
mov rax, SYSCALL_WRITE
@codetalks-new
codetalks-new / CommentView.swift
Created July 2, 2015 08:43
一个简单的 CommentView ,模仿网易新闻评论框
//
// CommentView.swift
// GuilinLegal
//
// Created by Haizhen Lee on 15/7/2.
// Copyright (c) 2015年 banxi1988 . All rights reserved.
//
import UIKit
@codetalks-new
codetalks-new / BuildTreeWithPreorderInorder.swift
Created July 2, 2015 05:29
Build Binary Tree with Preorder and Inorder
func buildTreeWithPreorder(preorder:[Int],andInorder inorder:[Int]) -> TreeNode?{
if preorder.isEmpty || inorder.isEmpty{
return nil
}
var branchList = [TreeNode]()
let root = TreeNode(val: 0)
branchList.append(root)
var preorderArray = [[Int]]()
@codetalks-new
codetalks-new / DrawBinaryTree.swift
Last active August 29, 2015 14:24
Swift 绘制二叉树类
import UIKit
class TreeNode{
let val:Int
var left:TreeNode?
var right:TreeNode?
init(val:Int){
self.val = val
}
}
@codetalks-new
codetalks-new / Main.java
Created June 27, 2015 12:47
Java 并发多线程的等待结果完成的问题
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.*;
import java.util.logging.Formatter;
/**
* Created by banxi on 15/6/27.
@codetalks-new
codetalks-new / LoadMoreControl.swift
Created June 23, 2015 03:16
LoadMoreControl like UIRefreshControl
//
// LoadMoreControl.swift
// GuilinLegal
//
// Created by Haizhen Lee on 15/6/19.
// Copyright (c) 2015年 banxi1988. All rights reserved.
//
import UIKit