- 博客(116)
- 资源 (6)
- 收藏
- 关注
原创 Redis lua usage
lua usagebasic command127.0.0.1:6379> EVAL "return redis.call('set', KEYS[1], ARGV[1])" 1 name zhangsan127.0.0.1:6379> EVAL "return redis.call('get', KEYS[1])" 1 namehash to memory127.0.0.1:6379> SCRIPT LOAD "return 'hello world'""5332031c
2022-02-23 07:19:31
466
原创 unittest source code learning
Structure#mermaid-svg-g3PbzysQX9n4xNTU .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-g3PbzysQX9n4xNTU .label text{fill:#333}#mermaid-svg-g3PbzysQX9n4xNTU .node rect,#mermaid-svg-
2021-06-09 10:20:03
479
4
原创 leetcode 122. Best Time to Buy and Sell Stock II
QuestionSay you have an array prices for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multip
2020-10-10 09:02:45
196
原创 leetcode 463. Island Perimeter
class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: """ grid = [[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]] """ ...
2020-09-02 09:01:42
118
原创 自动为 Gatsby网站中的 Markdown 页面添加 sidebar
我想在Gatsby网站上创建Markdown页面时自动添加侧边栏。有一个 starter “ gatsby-gitbook-starter” 可以支持markdown文件的侧边栏,但仅支持1级。 我希望能够支持更多级别。
2020-08-18 17:51:31
453
原创 binary search - leetcode 33. Search in Rotated Sorted Array
1. questionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in the array return its index, otherwise ret
2020-08-12 09:43:38
175
原创 quick sort
"""step 1 : maintain the following structurea[l] ...... ,,,,,, < a[l] > a[l] j istep 2: in the end, swap(l, j), return j. .....a[l] ,,,,,, < a[l] > a[l] j iFor examp
2020-07-15 08:42:13
158
原创 Python slice notation [:] - leetcode 189. Rotate Array
1. a[start:stop:step]q = "12345"w = q[0:2:1] # [0, 2)print(f"w: {w}")# w: 12w = q[::-1] # if step is negative, reverse traverseprint(f"w's type: {type(w)} w: {w}")# w's type: <class 'str'> w: 54321w = q[::-2]print(f"w: {w}") # w: 5312.
2020-06-29 15:11:39
192
原创 python 模块导入注意事项
入口文件不能使用相对导入。import .module1if __name__ == '__main__': print("hello")ImportError: attempted relative import with no known parent package相对导入不能超过顶层包。app||----module1| |---f1.py||----module2| |---f2.py||----main.py# f2.p.
2020-06-19 13:38:07
242
原创 slide window & +Counter() : leetcode 438. Find All Anagrams in a String
def findAnagrams_leetcode(self, s: str, p: str) -> List[int]: if len(s) < len(p): return [] p_chars = Counter(p) i = 0 j = len(p) window = Counter(s[i:j]) results = [] while j &...
2020-06-12 15:21:29
190
原创 subsets : zero left padding : leetcode 78
leetcode 78求解序列的所有子集。例如: [1, 2, 3].所有子集为:[ [ ], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3] ]其中一种解题思路为:使用2进制来表示,组合中是否包含某个元素。例如 001–> [3], 101–>[1, 3], 111–>[1, 2, 3]因此只有列出 [0, 2n) 的2进制表示,就可以求出所有的子集。求解2进制表示时,有一个“zero left padd
2020-06-02 07:37:11
129
原创 regular expression examples
import rea = "java|Python|c0123tttyyyuu9"res = re.search("java\|Python\|c([0-9]+)tttyyyuu9", a)print(res.group(0)) # whole stringprint(res.groups()) # matched string in ()print(res.group(1)) # matched string in ()print(res.span(1)) # span of group 1
2020-05-29 10:00:55
156
原创 backtrace&usage of slice notation[:] - leetcode 77. Combinations
def combine(self, n: int, k: int) -> List[List[int]]: """ Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] :param n:...
2020-05-26 09:07:52
190
1
原创 build tree & sum path (usage of list[0]) - 404. Sum of Left Leaves
from collections import dequeclass TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = rightclass Solution: def printTreeCore(self, root, preorder=True): if not
2020-05-22 06:37:11
184
2
原创 算法-计算1的个数及python sort函数的多层排序
leetcode: 1356.Sort Integers by The Number of 1 Bits1. 计算数字中bit1的个数在这里,计算1 bit 的个数使用的是 减1再 bit and的方式。例如 9的二进制表示为 1001:(1)减1 后为 1000, 1001&1000 = 1000.(2)1000 减1 后为 0111, 1000&...
2020-04-07 07:37:11
314
原创 算法-动态规划3
根据在算法-动态规划2里提到的思路,让我们来解决一个组合问题 :leetcode 第77题。0 问题描述给定2个整数n,k,求出从[1,…,n]中取k个数字的所有组合。例如 n=4, k=2就是从[1,2,3,4]中取2个数字的所有组合。结果为:[[1, 2], [1, 3], [2, 3], [1, 4], [2, 4], [3, 4]]1 递归解法(1)假设组合中不包含 第n个...
2020-04-03 11:57:04
172
原创 算法-动态规划2
记得5年前写过一篇关于动态规划的博客。最近重新学习基本算法,对动态规划有了更深入的体会。感谢慕课网上《玩转算法面试-- Leetcode真题分门别类讲解》这门课程的老师liuyubobobo,这门课真的不错。对于“背包问题”,现在可以按照自己的思路写出来代码了,虽然运行一下发现有问题,经过修改调试,最终可以完成。这样的过程,我认为比记住一些代码,然后一遍把代码写对,是要好很多了。要把动态规划的...
2020-04-02 08:52:37
171
原创 design pattern
1 adapterclass Cat: def __init__(self): self.name = "cat" def mom(self): print("mom!")class Dog: def __init__(self): self.name = "dog" def bark(self): ...
2020-02-23 09:00:11
151
原创 sort & search algorithm
def quick_sort(array): if len(array) < 2: return array else: pivot_index = 0 pivot = array[pivot_index] less_part = [i for i in array[pivot_index+1:] if i &...
2020-02-17 17:49:16
162
原创 parameter passing
print("""There is only one type of parameter passing in Python, which is object reference passing.In the function body, mutable and immutable objects have different behaviours.""")def fl(l): ...
2020-02-10 12:36:43
302
原创 GIL & coroutine & performance
GILone byte code instruction is thread safe.The following code has 3 byte code instructions, so it’s not thread safe.import disdef incr_list(l): l[0] += 1if __name__ == '__main__': ...
2020-02-09 18:51:42
116
原创 exception
‘docs.python.org’ about ‘exception’def exception_example(): a = 0 try: a = 1/0 except Exception as e: print(e) else: a = 1 finally: print(a)cl...
2020-02-09 08:01:26
312
原创 unit test & mock
external_module.pydef multiply(x, y): return x*y+1main.pyimport unittestfrom unittest import mockfrom unittest.mock import patch#### pay attention to the way we import 'multiply'### in t...
2020-02-08 13:11:16
150
原创 shallow copy & deep copy
import copydef shallow_n_deep_copy(): a = {'a': [1, 2, 3]} b = a.copy() print('a:', a, 'b:', b) a['a'].append(4) print('a:', a, 'b:', b) c = copy.deepcopy(a) a['a'].appe...
2020-02-04 13:41:22
120
原创 collections
from collections import namedtuplefrom collections import dequefrom collections import OrderedDictdef nametuple_example(): Person = namedtuple("hahaha", "name, age, gender") alice = Perso...
2020-02-04 06:34:56
130
原创 gdb debug summary
gdb attach programgdb -p $(pidof rcpd)gdb use symbolgdb att 2271 -s cips_app.symgdb create struct params(gdb) call malloc(sizeof(dps_l1xc_info_t))(gdb) p *(dps_l1xc_info_t *)$1$3 = {sr...
2019-09-19 16:12:00
189
原创 my docker tutorial
add mirrorfind exist imagefind an image in dock hub.https://hub.docker.com/r/fnndsc/ubuntu-python3/dockerfileget&run imagedocker pull fnndsc/ubuntu-python3docker run -itd --name ubu...
2019-09-01 12:51:13
210
原创 jenkins
use this plugin to store the parameters of your last build.https://wiki.jenkins.io/display/JENKINS/Persistent+Parameter+Plugin
2019-08-22 22:04:43
170
原创 报文数据的txt文件 转换成wireshark可以识别的k12文件
implement a python app which can covert hex raw packet data to k12 file.Wireshark can open the k12 file and parse the packet content.#########1.txt###########09002b00 00050020 8fca980d 81000...
2019-07-17 13:40:02
1696
原创 vscode related
If you want to find the older version of VScode, you can click the "updates" tag in its official web.like:https://code.visualstudio.com/updates/v1_27vscode installhttps://blog.youkuaiyun.com/bat...
2019-06-13 15:35:23
490
原创 axure design
axure designhttps://www.axureshop.com/https://www.iconfont.cn/
2019-06-06 14:51:33
209
原创 适配器模式(c语言实现)
在这里用c实现了类似于java的接口。#include <stdio.h>#include <stdlib.h>#include <cassert>typedef struct _Duck{ void (*fly)(struct _Duck* b); void (*quack)(struct _Duck* b);}...
2019-06-05 16:09:18
742
原创 command模式(c语言实现)
2014年写过一篇实现,重读一遍《设计模式》,参考网上的一篇文章,又重新写了一遍。我体会到,c++的类在c语言里面用struct代替之后,c++的this指针可以通过传入struct本身的指针来完成。而在command模式里的Command实际上既包含了对象(pData),又包含了命令接口(exe)。#include <stdio.h>#include <...
2019-06-01 14:22:44
1569
原创 yqzj微信公众号&小程序开发
《微信开发入门》文档中 list = [token, timestamp, nonce] list.sort() sha1 = hashlib.sha1() map(sha1.update, list)//此处错误 hashcode = sha1.hexdigest()应...
2019-01-23 21:15:18
817
原创 a bug related with extern
in file a.cunsigned int my_length = 0x12345678;**********************************************int file main.cextern unsigned short my_length;int main(){printf("0x%x\n", my_length);
2016-11-28 14:38:59
280
原创 struct union and endian
#pragma pack(push, 1)typedef union { struct {# ifdef CS_BIG_ENDIAN cs_uint16 rsrvd1 :4; cs_uint16 output_src_sel :3; cs_uint16 invert_output :1; cs_uint16 invert_input
2016-09-27 14:12:05
440
flappy_bird_pygame.zip
2020-06-29
python-3.8.1-docs-html.zip
2020-02-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人