- 博客(78)
- 收藏
- 关注
转载 [python] attribute fetch
def class_lookup(cls, name): v = cls.__dict__.get(name) if v is not None: return v, cls for i in cls.__bases__: v, c = class_lookup(i, name) if v is not None: ...
2018-05-29 21:56:43 479
原创 [python] decorator implemented with class to wrap class method
# python2Python 2.7.5 (default, Dec 8 2017, 16:39:59) [GCC 4.8.5 20150623 (Red Hat 4.8.5-25)] on linux2Type "help", "copyright", "credits" or "license" for more information.&a
2018-05-22 16:22:09 249
原创 [python] __get__ of descriptor
class Property: def __init__(self, fget=None, fset=None, fdel=None, doc=None): self.fget = fget self.fset = fset self.fdel = fdel self.__doc__ = doc def __get_...
2018-05-17 19:53:53 321
原创 [python] co_lnotab
co_lnotab is the mapping from bytecode to code line number.# python3.6Python 3.6.5 (default, Apr 16 2018, 16:19:06) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linuxType "help", "copyright", "cr...
2018-05-15 16:02:31 785
原创 [python] understanding output of dis
in python, use range for loop is much faster than while, why?>>> timeit.timeit("for i in range(100): pass")1.6118687279995356>>> timeit.timeit("i = 0\nwhile
2018-05-09 19:57:50 245
原创 decorator to count the call
class decorator:class tracer0: def __init__(self, func): self.calls = 0 self.func = func def __call__(self, *args): self.calls += 1 print("call %s to %s" % ...
2018-04-27 17:02:34 238
原创 python learning notes
PART I in new-style class, implicit attribute fetch starts at class instead of instance. X[I] is equivalent to X.__getitem__(I) in old-style class. X[I] is equivalent to type(X).__getitem__(X, I) i...
2018-04-19 11:19:21 308
原创 execution of Linux commands in Python.
1. os.systemout = os.system(command_to_use)This is implemented by calling the Standard C function system(), and has the same limitations. the return value is the exit status of the process enc...
2018-04-16 18:19:15 261
转载 refactoring in python[note 1]
note taking from online video course: https://www.safaribooksonline.com/library/view/refactoring-in-pythonwhy we should refactor our code?improve readabilityreduce time to find bugsto make l...
2018-04-03 12:22:49 288
原创 learning avocado [simple test]
use avocado list to get tests list.# avocado listError running method "configure" of plugin "vt": argument --vt-config: conflicting option string(s): --vt-configError running method "configur...
2018-04-02 15:55:53 362
原创 python descriptor
reference: https://docs.python.org/3/howto/descriptor.html http://www.cs.utexas.edu/~cannata/cs345/Class%20Notes/15%20python_attributes_and_methods.pdf python attribute search summary: 1. retr...
2018-03-29 14:32:04 209
原创 learning avocado [phase 2 - decorators]
source code https://github.com/avocado-framework/avocado/blob/master/avocado/core/decorators.py avocado.fail_on(exceptions) avocado.skip(msg=None) avocado.skipIf(condition, msg=None) avocado.skip...
2018-03-28 20:01:15 231
原创 learning avocado [phase I]
install avocado# pip install avocado-frameworkinstall other plugins# pip search avocado-framework-plugin | grep avocado-framework-pluginavocado-framework-plugin-glib (59.0) ...
2018-03-28 17:32:44 491
转载 difference between semaphore and mutex
http://saurabhsinhainblogs.blogspot.in/2014/02/difference-between-mutex-vs-semaphore.html https://www.geeksforgeeks.org/mutex-vs-semaphore/mutex is locking mechanism while semaphore is signaling me...
2018-03-23 16:27:26 201
原创 python re note[part1]
python raw string notation to suppress backslash: r"\n" is a two character string.if A and B are both regex, AB is regex. .: any character except a newline.^: start of string.*: 0 or more r...
2018-02-23 12:39:06 215
原创 class and type for classic and new-style class.
# python2Python 2.7.5 (default, Dec 8 2017, 16:39:59) [GCC 4.8.5 20150623 (Red Hat 4.8.5-25)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> class C: pass...
2018-02-05 14:02:40 297
原创 __getattr__ in python
Attribute fetch in classes and class instances: from https://docs.python.org/2/reference/datamodel.html: For classes class attribute references are translated to lookups in dictionary: C.x => C.__d
2018-02-02 14:53:45 244
原创 Downgrade with rpm and yum
Two ways to downgrade a program 1.# rpm -Uvh --oldpackage [filename]2.# yum downgrade [packagename]
2018-02-02 14:00:49 305
原创 fetch attribute in python 3.x
class Person: def __init__(self, name, job=None, pay=0): self.name = name.lower() self.job = job self.pay = pay def lastName(self): return self.name.split()[-1]
2018-01-10 18:56:08 269
原创 one-shot iteration
python学习手册514页def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res)s1 = '123's2 = 'abcdef'print(list(myzip(s1, s2)))这段代码在2.6中运
2018-01-03 19:44:33 397
原创 python: learn yield and send[part 1]
Sample code def gen(): for i in range(3): x = yield i print(x)>>> g = gen()>>> next(g)0>>> next(g)None1>>> next(g)None2>>> next(g)NoneTraceback (most recen
2017-12-29 14:41:10 231
原创 python state of nested function
def maker(N): def action(X): return X ** N return action# nonlocaldef maker1(N): state = 1 def action(X): nonlocal state print('%d th call.' % state) s
2017-12-27 22:05:56 383
原创 stack overflow[part2]
Target program:// vulnerable.c#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]) { char searchstring[100]; if(argc > 1) strcpy(searchstring, ar
2017-06-19 21:46:35 566
原创 stack overflow[part1]
C program:#include <stdio.h>#include <stdlib.h>#include <string.h>int check_authentication(char *password) { char password_buffer[16]; int auth_flag = 0; strcpy(password_buffer, passwor
2017-06-18 12:42:02 575
转载 tail recursion
traditional recursion: perform recursion first, then take the return value of the recursive call and calculate the result. You don’t get the result of your calculation until you have returned from e
2017-06-15 11:30:40 610
原创 gdb and C memory layout
A simple C program:#include <stdlib.h>int main(){ int i; for (i = 0; i < 10; ++i) printf("Hello_world!\n"); return 0;}lyu@ubuntu:~/Desktop/work$ gdb -q ./a.outReading symbols fr
2017-06-10 16:52:05 659
原创 [leetcode]Insert Interval
57. Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their st
2017-06-08 14:12:29 285
原创 [leetcode]Jump Game II
45. Jump Game IIGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Yo
2017-06-07 21:33:40 329
原创 C++ virtual table
Best reference explaining virtual table and dynamic binding 1.
2017-06-01 22:57:53 310
原创 [leetcode]Search for a Range
34. Search for a RangeGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(
2017-05-31 11:19:20 317
原创 [leetcode]Longest Valid Parentheses
32. Longest Valid ParenthesesGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parenthese
2017-05-28 11:02:07 361
原创 [leetcode]排列类问题
31. Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the
2017-05-26 20:45:38 345
原创 [leetcode]Implement strStr()
28. Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.字符串模式匹配: 1.brute force:int strStr(string haystack, st
2017-05-26 17:26:10 343
原创 [leetcode]单链表类题目总结(应用双指针)
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */24. Swap Nodes in Pairs Given a linked lis
2017-05-25 21:49:05 730
原创 [leetcode]Longest Common Prefix
14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings.我的代码:string longestCommonPrefix(vector<string>& strs){ string lcp; if (strs.emp
2017-05-25 15:14:39 330
原创 [leetcode]Container With Most Water
11. Container With Most Water Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (
2017-05-25 12:17:22 272
原创 [leetcode]Median of Two Sorted Arrays
4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n
2017-05-19 17:36:49 495
原创 Leetcode string题目中的双指针模板
leetcode中有不少求最长或者最短满足特定条件子串的长度,这些题目都有共性:使用双指针,且使用哈希表记录字符出现的次数。有高人总结的模板,配合一下总结的该类问题食用更加! Template:int findSubstring(string s) { vector<int> map(128, 0); int counter = 0; // check wh
2017-05-19 16:30:09 1063
原创 [leetcode]求和类问题
Two sum i Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use
2017-05-19 11:22:17 365
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人