Skip to content

Instantly share code, notes, and snippets.

import win32com.client as win32
import time
import sys
import os
import shutil
def sendonemail(addr = "", attach = "", subject = ""):
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
@prehistoricpenguin
prehistoricpenguin / stringtohexarray.cpp
Created March 27, 2014 08:22
"0123456789abcdef" - > 0x12 0x34 0x56 0x78 ...
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <string>
#include <vector>
#include <stdexcept>
#include <iostream>
int chartoint(char c) {
const char* buf = "0123456789abcdef";

Latency Comparison Numbers

Type time ms comment
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 300 ns 20x L2 cache, 200x L1 cache

c++11 - the new standard

auto and init list

for (const auto x : { 1, 2, 3}}) cout << x <<  endl;

In-class member initializers

class A {
#include <vector>
#include <iostream>
#include <cstdio>
using namespace std;
pair<int, int> findNumber(const vector<int>& vec) {
int xsum = 0;
int sz = vec.size();
// calc for total arrary
string generate_code() {
const int kcodelength = 25;
char res[kcodelength + 10];
string buffer = "1234567890abcdefghijklmnopqrstuvwzyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int len = buffer.length();
int idx = 0;
for (int i = 0; i < kcodelength; ++i) {
char tmp = buffer[rand() % len];
// A simple demo aimed to test the time efficiency for the find operation
// in C++ STL containers, used in vector,map and unordered_map, respectively.
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <cstdio>
#include <ctime>
int
binary_search_first_position(int *A, int n, int target) {
int end[2] = { -1, n };
while (end[0] + 1 < end[1]) {
int mid = (end[0] + end[1]) / 2;
int sign = (unsigned)(A[mid] - target) >> 31;
end[1-sign] = mid;
}
int high = end[1];
if (high >= n || A[high] != target)
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
using namespace std;
#include <iostream>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int msize = 500;