Skip to content

Instantly share code, notes, and snippets.

package errors
import (
"fmt"
"reflect"
"strconv"
)
type CodedError struct {
code int64 // 错误码
@ictlyh
ictlyh / OutlookSubjectAndAttachmentChecking
Created July 29, 2017 02:46
Check whether email has a subject and attachment for Outlook
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngres As Long
'检查邮件是否添加附件
If InStr(1, Item.Body, "附件") <> 0 Then
If Item.Attachments.Count = 0 Then
Application.Explorers(1).Activate
lngres = MsgBox("邮件内容中包含“附件”,但没有上传附件!" & Chr(10) & "仍然发送?", _
vbYesNo + vbDefaultButton2 + vbQuestion, "提示")
If lngres = vbNo Then
@ictlyh
ictlyh / list_server_variable.php
Created April 5, 2017 06:57
PHP to list server variables of predefined variable $_SERVER
<?php
/* Try http://mutouxiaogui.cn/blog/list_server_variable.php?v1=1&v2=2 in your browser */
$indicesServer = array('PHP_SELF',
'argv',
'argc',
'GATEWAY_INTERFACE',
'SERVER_ADDR',
'SERVER_NAME',
'SERVER_SOFTWARE',
'SERVER_PROTOCOL',
@ictlyh
ictlyh / list_server_variable.php
Created April 5, 2017 06:57
PHP to list server variables of predefined variable $_SERVER
<?php
/* Try http://mutouxiaogui.cn/blog/list_server_variable.php?v1=1&v2=2 in your browser */
$indicesServer = array('PHP_SELF',
'argv',
'argc',
'GATEWAY_INTERFACE',
'SERVER_ADDR',
'SERVER_NAME',
'SERVER_SOFTWARE',
'SERVER_PROTOCOL',
@ictlyh
ictlyh / redirect.php
Last active April 5, 2017 07:55
PHP page redirect with parameters
<?php
/* redirect mutouxiaogui.cn/blog to stay-stupid.com, the parameters remain unchanged */
/* notify search engines that a page has been permanently moved to another location */
header('Status: 301 Moved Permanently', false, 301);
/* redirect to another page */
$redirect_url = 'http://stay-stupid.com/'.basename($_SERVER['REQUEST_URI']);
header('Location: '.$redirect_url);
@ictlyh
ictlyh / libpq-epoll.cpp
Created December 30, 2016 01:56
postgresql epoll demo
/*
* Demo of libpq epoll.
* Build: g++ libpq-epoll.cpp -o libpq-epoll -lpq
* Run: ./libpq-epoll
*/
#include <arpa/inet.h>
#include <cstdlib>
#include <cstring>
#include <errno.h>
@ictlyh
ictlyh / test-gflag.cc
Created November 30, 2016 13:42
Demo of gflags
/*
* Demo of gflags
* Build: g++ test-gflags.cc -o test-gfalgs -lgflags
* // ERROR: illegal value '-1' specified for uint64 flag 'u64'
* ./test-gflags.out --b=false --i32=-1 --i64=1 --u64=-1 --d=10.01 -s="string value"
* // ERROR: failed validation of new value '11' for flag 'i32'
* ./test-gflags.out --b=false --i32=11 --i64=1 --u64=1 --d=10.01 -s="string value"
* ./test-gflags.out --b=false --i32=1 --i64=1 --u64=1 --d=10.01 extraa extrab extrac
*
* Refer to gflags.h for more detail help message of structs and function.
@ictlyh
ictlyh / test-glog.cc
Created November 30, 2016 12:42
glog(google log system for cpp) demo
/*
* Demo of glog.
* Build: g++ test-glog.cc -o test-glog.out -lglog
* Run: export GLOG_log_dir=/path/to/logdir && ./test-glog
*/
#include <glog/logging.h>
int main(int argc, char* argv[]) {
google::InitGoogleLogging(argv[0]);
@ictlyh
ictlyh / producer-consumer
Created November 30, 2016 10:55
Producer and consumer demo in concurrent queue. c++ multi-threading.
// concurrent-queue.h
#ifndef CONCURRENT_QUEUE_H_
#define CONCURRENT_QUEUE_H_
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
template <typename T>
@ictlyh
ictlyh / whiptail-demo.sh
Created November 30, 2016 10:23
Demo of whiptail
#!/bin/bash
# Demo of check list using whiptail
whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 78 4 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF