]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authorAceVest <zhaoyanbai@126.com>
Wed, 1 Mar 2017 15:49:28 +0000 (23:49 +0800)
committerAceVest <zhaoyanbai@126.com>
Wed, 1 Mar 2017 15:49:28 +0000 (23:49 +0800)
12 files changed:
.gitignore
learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift
learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate
learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate
learn/cc/string.cc [new file with mode: 0644]
learn/doc/mac_bash_profile
learn/doc/vimrc
learn/python/dictionary.py
learn/python/list.py
learn/python/set.py
learn/python/utils.py
tools/comm/htc.c

index 687f5a3b2a1b9f825c5ed392dfc552437e45fbe8..9d63951b13fe9037e306ba5dbfa2064c548bd33e 100644 (file)
@@ -7,4 +7,5 @@ ish
 *.swp
 *.ef
 *.conf
+*.diff
 dvwa
index 1f82280371981991e60cdbe212cf7b8f6af9e3e4..4890fa091ed640baf8c64a15542d668e8496ec48 100644 (file)
 
 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)..<welcome.endIndex
+welcome.removeSubrange(range)
+print(welcome)
+
+
+
+// ############# Working with Characters ################
 for c in str.characters {
     print(c, terminator: "")
 }
 print()
 
+print("The String is: \(str)")
+
+
 // Print separator & terminator
 var company:Array<String> = [ "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
index dde461ff1d914a43b20e7ded157907d50ca6841a..a208718ee0cd558cb5f6d0c14f210a5583fb4d80 100644 (file)
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
index bb26f9734b72b24ab42034dd4560642fa9ed7102..5079663a0e3f7fff8127c4e2fbe7669eb2b4868c 100644 (file)
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 (file)
index 0000000..293e22a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: string.cc
+ *      Author: Zhao Yanbai
+ *              2017-01-02 12:04:22 Monday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+#include<iostream>
+#include<string>
+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;
+}
index 591b4fb883a0f911ec7aa0e3b6b4db0bdbbb3fe1..995e6488a755dee11358b6e0faa6435504ed0f20 100644 (file)
@@ -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/'
index 851a41ec10563a0d9a1860bc41d67de7d9136dd8..cf110be608418935841bf854f4bdaeb3bfc3aa12 100644 (file)
@@ -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
index 64259a764a14f9897d5d5557333cc98965ab6066..68ff7cc19c8ffec3ac7b49285071bc8d7ee56888 100755 (executable)
@@ -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],
index 856c021cba6b527e0c96af46806aae44ea0f6847..6354dd56c13c692f14ec425e04b9dc71918ce243 100755 (executable)
@@ -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
+
index 43771fc9d679780c5137d477c401d34731561039..d5c7322ce794c25d34f1afc3c86cc25f3a9866df 100755 (executable)
@@ -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 { }
index 9dd28ab926425f8800fda482aa71720373e390b8..175e0d6afb145f9fca2aed9454e62666676be59c 100755 (executable)
@@ -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()
index 7b4b549d7b064e08aeaf1a4354921a4f5cb62dcf..b5be73b78087fb49eb5af7c560aa9074d05c0d49 100644 (file)
@@ -20,9 +20,9 @@
 #include<stdio.h>
 int main()
 {
-       char ch;
+       unsigned int ch;
        while(scanf("%x",&ch) != EOF)
-               printf("%c",ch);
+               printf("%c",(unsigned char)ch);
 
        return 0;
 }