自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

KusanoNEU的博客

No day but today.

  • 博客(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 457

原创 [python] decorator implemented with class to wrap class method

# python2 Python 2.7.5 (default, Dec 8 2017, 16:39:59) [GCC 4.8.5 20150623 (Red Hat 4.8.5-25)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &a

2018-05-22 16:22:09 233

原创 [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 303

原创 [python] co_lnotab

co_lnotab is the mapping from bytecode to code line number. # python3.6 Python 3.6.5 (default, Apr 16 2018, 16:19:06) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux Type "help", "copyright", "cr...

2018-05-15 16:02:31 736

原创 [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 221

原创 [python] closure

2018-05-09 17:02:37 323

原创 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 221

原创 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 276

原创 execution of Linux commands in Python.

1. os.system out = 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 237

转载 refactoring in python[note 1]

note taking from online video course: https://www.safaribooksonline.com/library/view/refactoring-in-python why we should refactor our code? improve readability reduce time to find bugs to make l...

2018-04-03 12:22:49 269

原创 learning avocado [simple test]

use avocado list to get tests list. # avocado list Error running method "configure" of plugin "vt": argument --vt-config: conflicting option string(s): --vt-config Error running method "configur...

2018-04-02 15:55:53 343

原创 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 192

原创 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 208

原创 learning avocado [phase I]

install avocado # pip install avocado-framework install other plugins # pip search avocado-framework-plugin | grep avocado-framework-plugin avocado-framework-plugin-glib (59.0) ...

2018-03-28 17:32:44 468

转载 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 184

原创 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 193

原创 class and type for classic and new-style class.

# python2 Python 2.7.5 (default, Dec 8 2017, 16:39:59) [GCC 4.8.5 20150623 (Red Hat 4.8.5-25)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class C: pass ...

2018-02-05 14:02:40 276

原创 __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 224

原创 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 273

原创 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 246

原创 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 379

原创 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) None 1 >>> next(g) None 2 >>> next(g) None Traceback (most recen

2017-12-29 14:41:10 214

原创 python state of nested function

def maker(N): def action(X): return X ** N return action # nonlocal def maker1(N): state = 1 def action(X): nonlocal state print('%d th call.' % state) s

2017-12-27 22:05:56 366

原创 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 531

原创 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 558

转载 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 591

原创 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.out Reading symbols fr

2017-06-10 16:52:05 631

原创 [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 267

原创 [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 313

原创 C++ virtual table

Best reference explaining virtual table and dynamic binding 1.

2017-06-01 22:57:53 293

原创 [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 299

原创 [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 350

原创 [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 316

原创 [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 327

原创 [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 688

原创 [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 317

原创 [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 258

原创 [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 479

原创 Leetcode string题目中的双指针模板

leetcode中有不少求最长或者最短满足特定条件子串的长度,这些题目都有共性:使用双指针,且使用哈希表记录字符出现的次数。有高人总结的模板,配合一下总结的该类问题食用更加! Template:int findSubstring(string s) { vector<int> map(128, 0); int counter = 0; // check wh

2017-05-19 16:30:09 1021

原创 [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 346

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除