From: AceVest Date: Wed, 1 Mar 2017 15:49:28 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=d5933c459ba6625373a9a5c418146f94146878b4;p=acecode.git ... --- diff --git a/.gitignore b/.gitignore index 687f5a3..9d63951 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ ish *.swp *.ef *.conf +*.diff dvwa diff --git a/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift index 1f82280..4890fa0 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift @@ -2,18 +2,134 @@ import UIKit -let str = "Hello, playground.小狗:🐶 锤子:🔨" +// String values can be constructed by passing an array of Character values +let catCharacters: [Character] = ["C", "a", "t", " ", "猫"] +let catString = String(catCharacters) +print(catString) + +// Character 加到String的方法 +var welcome = "Hello World" +let exclamationMark: Character = "!" +welcome.append(exclamationMark) +print(welcome) + +// ############# Type Alias ################ +typealias AudioSample = UInt + +let maxAmplitudeFound = AudioSample.max + + +// ############# Tuple ################ +let http404Error = (404, "Page Not Found") +let (httpRetCode, _) = http404Error +print("Http RetCode \(httpRetCode) Error Message \(http404Error.1)") + +let httpStatus = (statusCode: 200, description: "OK") +print("Http RetCode \(httpStatus.statusCode) Message \(httpStatus.description)") + + +// ############# Optionals ################ +let possibleNumber = "123" +let convertNumber : Int? = Int(possibleNumber) // of type Int? + +if convertNumber != nil { + print("ConvertNumber is \(convertNumber)") + print("ConvertNumber is \(convertNumber!)") +} else { + print("ConvertNumber is nil") +} + +// ############# Optionals Binding ################ +if let actualNumber = Int(possibleNumber) { + print("\"\(possibleNumber)\" has an integer of \(actualNumber)") +} else { + print("\"\(possibleNumber)\" could not to be converted to an integer") +} + +if let firstNumber = Int("4"), let secondNumber = Int("42"), firstNumber < secondNumber && secondNumber < 100 { + print("\(firstNumber) < \(secondNumber) < 100") +} + +// ############# Implicitly Unwrapped Optionals ################ +let possibleString: String? = "An Optional String" +let forcedString: String = possibleString! + +let assumedString: String! = "An Implicitly Unwrapped Optional String" +let implicitString: String = assumedString + +print("\(possibleString!) \(forcedString) \(assumedString) \(implicitString)") + +// ############# Nil-Coalescing Operator ################ +let defaultColorName = "yellow" +var userDefinedColorName: String? +// 等价于 userDefinedColorName == nil ? defaultColorName : userDefinedColorName +var colorNameToUse = userDefinedColorName ?? defaultColorName +print(colorNameToUse) + +userDefinedColorName = "red" +colorNameToUse = userDefinedColorName ?? defaultColorName +print(colorNameToUse) +// ############# Nil-Coalescing Operator ################ +for index in 1...5 { + print("Closed Range Operator \(index) of [1,5]") +} + +for index in 0..<5 { + print("Half-Open Range Operator \(index) of [0,5)") +} + +var word = "cafe" +print("the number of characters of \(word) is \(word.characters.count)"); +word += "\u{301}" +print("the number of characters of \(word) is \(word.characters.count)"); + + +let str = "Hello, playground.小狗:🐶 锤子:🔨" // Index -let strInx:String.Index = str.startIndex +var strInx:String.Index = str.startIndex str.index(after: strInx) -print(strInx) +print(str[strInx]) +for strInx in str.characters.indices { + print("\(str[strInx])", terminator: "") +} +print() +// utf8 编码格式 +for c in str.utf8 { + print(c, terminator: "-") +} +print() + +// unicode +for c in str.unicodeScalars { + print("\(c)\t\(c.value)") +} + +welcome.insert("~", at: welcome.endIndex) +print(welcome) +// contentsOf 是一个 Collection 所以要加 .characters +welcome.insert(contentsOf: " Hello Swift".characters, at: welcome.index(before: welcome.endIndex)) +print(welcome) + +welcome.remove(at: welcome.index(before: welcome.endIndex)) +print(welcome) + +let range = welcome.index(welcome.endIndex, offsetBy: -12).. = [ "Apple", "Google", "Facebook", "Tencent" ] print(company[0], company[1], company[2], company[3], separator: "#", terminator: " $$$$$\n") @@ -101,4 +217,4 @@ for value in DictD.values.sorted() { } let keys = [Int](DictD.keys) -print(keys) +print(keys) \ No newline at end of file diff --git a/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index dde461f..a208718 100644 Binary files a/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index bb26f97..5079663 100644 Binary files a/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/learn/cc/string.cc b/learn/cc/string.cc new file mode 100644 index 0000000..293e22a --- /dev/null +++ b/learn/cc/string.cc @@ -0,0 +1,34 @@ +/* + * ------------------------------------------------------------------------ + * File Name: string.cc + * Author: Zhao Yanbai + * 2017-01-02 12:04:22 Monday CST + * Description: none + * ------------------------------------------------------------------------ + */ +#include +#include +using namespace std; + +int main(int argc, char *argv[]) { + + string s = "Hello World!!\n"; + decltype(s.size()) punct_cnt = 0; + + for(auto c : s) { + cout << c; + if(ispunct(c)) { + punct_cnt++; + } + } + + cout << punct_cnt << " punctuation characters in " << s; + + for(auto &c : s) { + c = toupper(c); + } + + cout << s; + + return 0; +} diff --git a/learn/doc/mac_bash_profile b/learn/doc/mac_bash_profile index 591b4fb..995e648 100644 --- a/learn/doc/mac_bash_profile +++ b/learn/doc/mac_bash_profile @@ -2,8 +2,8 @@ #HISTCONTROL=ignorespace # 命令前加空格避免记入历史 HISTCONTROL=ignoreboth -export PATH=/usr/local/sbin:$PATH #export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" +export PATH=/usr/local/sbin:$PATH export PATH=/Users/Ace/.local/bin:$PATH export GOBIN=/Users/Ace/.local/bin export PATH=/Users/Ace/workspace/github/metasploit-framework:$PATH @@ -18,3 +18,4 @@ alias cls='clear' alias grep='grep --color' alias egrep='egrep --color' alias msf='msfconsole' +alias cdw='cd ~/workspace/' diff --git a/learn/doc/vimrc b/learn/doc/vimrc index 851a41e..cf110be 100644 --- a/learn/doc/vimrc +++ b/learn/doc/vimrc @@ -95,10 +95,10 @@ set nobomb " "为不同的文件类型设置不同的空格数替换TAB -"autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set ai -"autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set sw=4 -"autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set ts=4 -"autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set sts=4 +autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set ai +autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set sw=4 +autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set ts=4 +autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set sts=4 "golang默认使用TAB "autocmd FileType go set ai diff --git a/learn/python/dictionary.py b/learn/python/dictionary.py index 64259a7..68ff7cc 100755 --- a/learn/python/dictionary.py +++ b/learn/python/dictionary.py @@ -29,6 +29,9 @@ print D for name, value in D.items() : print "{0:10} : {1:10d}".format(name, value) +D = {x:x**2 for x in range(10)} +print(D) + D = dict(a=1, b=2, c=3) print D @@ -38,17 +41,21 @@ file_sz = {name : os.path.getsize(name) for name in os.listdir(".")} for item in file_sz.items() : print "{1}:\t{0}".format(item[0], item[1]) - - - x = dict() for i in range(0, 10) : x[i] = x.get(i, i) for i in sorted(x.keys()) : - print x[i] + print x[i], +print("") +# Another Make Empty Dictionary Method +x = { } +for i in range(0, 10) : + x[i] = x.get(i, i) +for i in sorted(x.keys()) : + print x[i], diff --git a/learn/python/list.py b/learn/python/list.py index 856c021..6354dd5 100755 --- a/learn/python/list.py +++ b/learn/python/list.py @@ -111,12 +111,34 @@ for k, v in reversed(zip(a, b)): for x in range(len(a)) : print x, +else : + print("") a += b print a +questions = ['name', 'quest', 'favorite color'] +answers = ['lancelot', 'the holy grail', 'blue'] +for q, a in zip(questions, answers): + print('What is your {0}? It is {1}.'.format(q, a)) + # 按下标循环 print L for i, v in enumerate(L) : - print i, v + print("[{0},{1}]".format(i, v)), +else : + print("") + + +# list 只适合快速后入后出,可以很方便地利用append 和 pop实现栈的功能 +# 要实现前出后入的队列功能就很慢,此时比较适合deque,用append 和 popleft实现 +from collections import deque + +queue = deque(['Apple', 'Microsoft', 'Google']) +queue.append('Tencent') +queue.append('Baidu') +queue.append('Alibaba') +queue.popleft() +print queue + diff --git a/learn/python/set.py b/learn/python/set.py index 43771fc..d5c7322 100755 --- a/learn/python/set.py +++ b/learn/python/set.py @@ -24,3 +24,9 @@ print "a&b: ", a&b print "a^b: ", a^b +Set = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} +print(Set) + + +#Empty Set +EmptySet = set() # not { } diff --git a/learn/python/utils.py b/learn/python/utils.py index 9dd28ab..175e0d6 100755 --- a/learn/python/utils.py +++ b/learn/python/utils.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # ------------------------------------------------------------------------ # File Name: utils.py @@ -16,6 +16,13 @@ print('OLDPWD:\t' + os.getenv('OLDPWD')) #判断一个对象是否可以迭代 -print isinstance('0xACE', collections.Iterable) -print isinstance([1, 2, 3, 4], collections.Iterable) -print isinstance(0xACE, collections.Iterable) +print(isinstance('0xACE', collections.Iterable)) +print(isinstance([1, 2, 3, 4], collections.Iterable)) +print(isinstance(0xACE, collections.Iterable)) + + +s = u'这是一个中文字符串' + +print('{!a}'.format(s)) # !a apply ascii() +print('{!s}'.format(s)) # !s apply str() +print('{!s}'.format(s)) # !r apply repr() diff --git a/tools/comm/htc.c b/tools/comm/htc.c index 7b4b549..b5be73b 100644 --- a/tools/comm/htc.c +++ b/tools/comm/htc.c @@ -20,9 +20,9 @@ #include int main() { - char ch; + unsigned int ch; while(scanf("%x",&ch) != EOF) - printf("%c",ch); + printf("%c",(unsigned char)ch); return 0; }