Google Breakpad is a cross platform crash handler which generates minidumps when your application crash. Users can send these minidumps to you and it contains valuable information allowing you to figure out why it crashed on them.
https://github.com/google/breakpad
https://chromium.googlesource.com/breakpad/breakpad
获取源码:
git clone https://chromium.googlesource.com/breakpad/breakpad
这里面略过了,但是记住要使用Python2.x,,Python3.x会报错
GYP(Generate Your Projects)是由 Chromium 团队开发的跨平台自动化项目构建工具,Chromium 便是通过 GYP 进行项目构建管理。
https://chromium.googlesource.com/external/gyp
git clone https://chromium.googlesource.com/external/gyp
安装gyp
cd gyp
python setup.py install
拷贝gyp文件夹到breakpad\src\tools文件夹下
E:\git\breakpad\src\tools\gyp>set GYP_MSVS_VERSION=2015
E:\git\breakpad\src\tools\gyp>gyp.bat --no-circular-check "../../client/windows/breakpad_client.gyp"
Warning: Missing input files:
..\..\client\windows\unittests\..\..\..\testing\googlemock\src\gmock-all.cc
..\..\client\windows\unittests\..\..\..\testing\googletest\src\gtest-all.cc
..\..\client\windows\unittests\..\..\..\testing\googletest\src\gtest_main.cc
然后会在目录E:\git\breakpad\src\client\windows下生成breakpad_client.sln工程。
#include <stdio.h>
#include "client/windows/handler/exception_handler.h"
using namespace google_breakpad;
static bool s_bMinidumpCallback(
const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded)
{
if (succeeded)
{
printf("dump guid is %ws\n", minidump_id);
}
else
{
printf("dump failed\n");
}
fflush(stdout);
return succeeded;
}
void errFun(int * p)
{
*p = 1;
}
int main()
{
google_breakpad::ExceptionHandler oExceptionHandler(
L".",
NULL,
s_bMinidumpCallback,
NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL
);
int * p = NULL;
errFun(p);
return 0;
}
运行测试代码会生成一个dump文件
把dump文件复制到exe和pdb的同一个目录下,然后把dump文件拖动到vs2015中去,点击右上角的 使用仅限本机进行调试。
https://github.com/google/protobuf
下载下面的3个压缩包。
protobuf-cpp-3.4.0.tar.gz
protobuf-cpp-3.4.0.zip
protoc-3.4.0-win32.zip
protobuf-cpp-3.4.0.tar.gz 和 protobuf-cpp-3.4.0.zip 是一样的,都是源代码。
protoc-3.4.0-win32.zip 是一个自动生成代码的工具。
将 protobuf-cpp-3.4.0.zip 解压
在 protobuf-3.2.0\cmake 目录下创建子目录 build/solution
进入目录 protobuf-3.2.0\cmake\build\solution,
执行命令 cmake -G “Visual Studio 14 2015” ../..
下面这是一些其他的Visual Studio版本:
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
然后就会在 solution 目录下生成 Visual Studio 的工程。
新建Message.proto文件
syntax = "proto2";
package tutorial;
message Person {
optional string name = 1;
optional int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
optional string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
message AddressBook {
repeated Person person = 1;
}
执行命令:
protoc -I=./ --cpp_out=./ Message.proto
然后会自动生成 Message.pb.h 和 Message.pb.cc 这两个文件。
这是测试文件:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include "Message.pb.h"
using namespace std;
int main()
{
printf("ProtoBuf Demo\n");
GOOGLE_PROTOBUF_VERIFY_VERSION;
tutorial::AddressBook oAddressBook;
printf("oAddressBook.person_size() = %d\n", oAddressBook.person_size());
::tutorial::Person* poPerson = oAddressBook.add_person();
poPerson->set_id(1);
poPerson->set_name("Person 1");
poPerson->set_email("person1@qq.com");
::tutorial::Person_PhoneNumber* poPhoneNumberHome = poPerson->add_phone();
poPhoneNumberHome->set_number("12345678");
poPhoneNumberHome->set_type(::tutorial::Person::HOME);
poPhoneNumberHome->set_type(::tutorial::Person_PhoneType_HOME);
::tutorial::Person_PhoneNumber* poPhoneNumberWork = poPerson->add_phone();
poPhoneNumberWork->set_number("87654321");
poPhoneNumberWork->set_type(::tutorial::Person::WORK);
//poPhoneNumberWork->set_type(::tutorial::Person_PhoneType_WORK);
printf("poPerson->phone_size() = %d\n", poPerson->phone_size());
printf("oAddressBook.person_size() = %d\n", oAddressBook.person_size());
string strOutput;
oAddressBook.SerializePartialToString(&strOutput);
printf("strOutput: [%s]\n", strOutput.c_str());
tutorial::AddressBook oAddressBookOutput;
oAddressBookOutput.ParseFromString(strOutput);
printf("oAddressBookOutput.person_size() = %d\n", oAddressBookOutput.person_size());
google::protobuf::ShutdownProtobufLibrary();
return 0;
}
git add -A .
处理所有的东西,包括untracked的文件和删除的文件。
如果不处理untracked的文件,只处理被修改过的和删除的文件。
git add -u .
https://leetcode.com/problems/intersection-of-two-arrays/description/
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2]
.
Note:
#include <iostream>
#include <vector>
#include <set>
using namespace std;
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2)
{
set<int> setNum1(nums1.begin(), nums1.end());
set<int> setNum2(nums2.begin(), nums2.end());
set<int> setResult;
set<int>::iterator iter = setNum1.begin();
while (iter != setNum1.end())
{
set<int>::iterator iter2 = setNum2.find(*iter);
if (iter2 != setNum2.end())
{
setResult.insert(*iter);
}
++iter;
}
vector<int> vecResult(setResult.begin(), setResult.end());
return vecResult;
}
};
int main()
{
vector<int> nums1 = { 1, 2, 2, 3 };
vector<int> nums2 = { 2, 2 };
vector<int> vecResult;
Solution o;
vecResult = o.intersection(nums1, nums2);
return 0;
}
https://leetcode.com/problems/reverse-vowels-of-a-string/description/
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = “hello”, return “holle”.
Example 2:
Given s = “leetcode”, return “leotcede”.
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
string reverseVowels(string s)
{
int iStart = 0;
int iEnd = s.size() - 1;
while (iStart < iEnd)
{
if (bIsVowels(s[iStart]) && bIsVowels(s[iEnd]))
{
vSwap(s[iStart], s[iEnd]);
iStart++;
iEnd--;
}
else if(!bIsVowels(s[iStart]))
{
iStart++;
}
else if (!bIsVowels(s[iEnd]))
{
iEnd--;
}
}
return s;
}
private:
bool bIsVowels(char c)
{
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
return true;
}
else
{
return false;
}
}
void vSwap(char & a, char & b)
{
char temp = a;
a = b;
b = temp;
}
};
int main()
{
Solution o;
string s = o.reverseVowels("aA");
return 0;
}