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
string truncateUTF8(const string& src, size_t tolen) | |
{ | |
string dst; | |
dst.reserve(tolen); | |
size_t i = 0; | |
while (dst.size() < tolen && i < src.size()) | |
{ | |
size_t step = 0; | |
if ((src[i] & 0x80) == 0x00) // 1字节 | |
step = 1; |
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
int main(int argc, char *argv[]) | |
{ | |
int sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
if (sockfd < 0) { | |
perror("new socket error"); | |
exit(-1); | |
} | |
struct sockaddr_in servaddr; | |
bzero(&servaddr, sizeof(servaddr)); |
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
#ifndef FAST_IN_H_ | |
#define FAST_IN_H_ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#define INPUT_BLOCK_SIZE 4096 * 512 | |
class FastInput |
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
#ifndef BUBBLE_SORT_H_ | |
#define BUBBLE_SORT_H_ | |
template <typename T> | |
void swap(T &a, T &b) | |
{ | |
T tmp = a; | |
a = b; | |
b = tmp; | |
} |
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
// 返回最后一个不大于 target 的位置 | |
template <typename T> | |
int binary_search(T *A, int low, int high, T target) | |
{ | |
while (low < high) { | |
int mid = (low + high) / 2; | |
target < A[mid] ? (high = mid) : (low = mid + 1); | |
} |
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
#ifndef BIT_MAP_H_ | |
#define BIT_MAP_H_ | |
#include <stdlib.h> | |
template <typename RANK = int> | |
class BitMap | |
{ | |
public: | |
BitMap(RANK n) : | |
capacity_(n), |
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
#include <sstream> | |
#include <string> | |
#include <boost/property_tree/json_parser.hpp> | |
int parseJson(const std::string &s) | |
{ | |
using boost::property_tree::ptree; | |
ptree pt; | |
std::stringstream ss(s); |
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
// struct filed only support uint* and string | |
// for string, there should be a value to represent the length of string | |
// packed | |
func WriteStructToBuffer(buffer *bytes.Buffer, data interface{}) error { | |
v := reflect.Indirect(reflect.ValueOf(data)) | |
if v.Kind() != reflect.Struct { | |
return errors.New("invaild type Not a struct") | |
} |
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
#include <stdio.h> | |
#include <openssl/aes.h> | |
#define AES_KEY_LENGTH 16 // aes-128 | |
std::string String2Hex(const unsigned char *src, size_t len) | |
{ | |
std::string dest = ""; | |
for (size_t i = 0; i < len; ++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
//转换为灰度图 | |
IplImage* pGrayImage = cvLoadImage( "image0.bmp", 0); | |
//利用Canny算子进行边缘检测 | |
IplImage * pCannyImg=cvCreateImage(cvGetSize(pGrayImage),pGrayImage->depth,1); | |
cvCanny(pGrayImage,pCannyImg,50,150,3); | |
//膨胀,使边缘轮廓闭合 | |
IplImage * pDilateImg=cvCreateImage(cvGetSize(pGrayImage),pGrayImage->depth,1); | |
IplConvKernel *rect_2; |
NewerOlder