This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makeCode() (code string) { | |
code = strconv.Itoa(rand.New(rand.NewSource(time.Now().UnixNano())).Intn(899999) + 100000) | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func add(ch chan int) { | |
for i := 0; i < 10; i++ { | |
ch <- i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func add(ch chan int) { | |
for i := 0; i < 10; i++ { | |
ch <- i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func listHandler(w http.ResponseWriter, r *http.Request) { | |
fileInfoArr, err := ioutil.ReadDir("./uploads") | |
check(err) | |
locals := make(map[string]interface{}) | |
images := []string{} | |
for _, fileInfo := range fileInfoArr { | |
images = append(images, fileInfo.Name) | |
} | |
locals["images"] = images | |
renderHtml(w, "list", locals) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<std::wstring> out_list; | |
boost::split(out_list, user_wstring1, boost::is_any_of(L" :;()[]<>,-+=/\\\r\n\t"), boost::token_compress_on); | |
if (2 != out_list.size()) | |
return; | |
int testvalue = _ttoi(out_list[0].c_str()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// send | |
PostMessage(MyhWnd, CWM_SOME_ERROR, 0, reinterpret_cast<LPARAM>(new string(the_exception.error_string)) ); | |
// receive | |
LPARAM CMyDlg::OnMyMessage1(WPARAM, LPARAM lParam) | |
{ | |
// Put in shared_ptr so it is automatically destroyed. | |
shared_ptr<string> msg = reinterpret_cast<string*>(lParam); | |
// Do stuff with message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// send | |
SendingMethod::SendMsgId( ... ) | |
{ | |
... | |
std::unique_ptr<MyParams> myParams( new MyParams(value1, value2, value3) ); | |
if (PostThreadMessage(MSG_ID, 0, reinterpret_cast<LPARAM>(myParams.release())) { | |
myParams.release(); // is postmessage failed | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *buffer = (char *)malloc(len); | |
std::shared_ptr<void> _free_ptr((void *)buffer, [](void *p){ | |
free(p); | |
}); | |
// 补充 | |
// FILE *fp = fopen("filepath", "rw"); | |
// use shared_ptr deleter do fclose(fp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建及获取元组内的对象 | |
std::tuple<double, std::string> tup1(3.14, "pi"); | |
auto tup2 = std::make_tuple("Hello World!", "abc", 3.14, 0); | |
const char* data = std::get<1>(tup2); // 得到abc | |
double len = std::get<2>(tup2); // 得到3.14 | |
// 拆箱:tie参数作为左值 | |
auto tup3 = std::make_tuple(3.14, 1, 'a'); | |
double a; | |
int b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 来自65010的请求转发到80 | |
iptables -t nat -A PREROUTING -p tcp --dport 65010 -j REDIRECT --to-port 80 | |
# 来自192.168.8.99的数据全部丢弃 | |
iptables -A INPUT -s "192.168.8.99" -j DROP |
OlderNewer