messageImage_1574339186475.jpg

messageImage_1574339145825.jpg


2019 美津濃接力賽

#相片大師 291035.jpg#PhotoDirector

290706.jpg290641.jpg


新浪微博API Oauth2.0 认证。。。

新浪微博API Oauth2.0 认证。。。

有一个人 U 想去银行 S 取钱。U 没辦去柜台,就委托朋友 C 去柜台。当C 去了银行S,给S说:我要帮 U 取钱。S 先验证 C 的身份,是合法公民。然后 S 打电话给 U。说:C 要帮你取钱,你确定么,确定的话就输入用户名和密码。 U 确定了。此时,S 就给了一个 钥匙给 C。说:我们不提供自动服务,给你钥匙,自己去库房取。然后 C 拿着钥匙,就去取钱了。取完之后给力 U。U 很感激。

http://rsj217.diandian.com/post/2013-04-17/40050093587

每个 开发者都有app_key 和 app_secret.  app_key称为密钥, app_secret为密匙。开发者和服务都知道。然后 ,开发者通过  app_key 和 app_secret 通过 一种加密(sha1)得到一个字符串secretcode 公钥。再把 app_key 和 secretcode 发送给服务器。服务器接收之后,将发送到 app_key和服务器存储的 app_secret 通过同样的加密手段得到一个 secretcode2 和发送过来的secretcode进行对比,如果一样,则可以证明是通过


fuzzy string search algorithm

http://stackoverflow.com/questions/491148/best-fuzzy-matching-algorithm

What is the best Fuzzy Matching Algorithm (Fuzzy Logic, N-Gram, Levenstein, Soundex ….,) to process more than 100000 records in less time? 

I suggest you read the articles by Navarro mentioned here: http://en.wikipedia.org/wiki/Fuzzy_string_searching Making your decision based on actual research is always better than on suggestions by random strangers.. Especially if performance on a known set of records is important to you.


How to See What DLL Files are used by Programs

http://www.ehow.com/how_4542929_what-dll-files-used-programs.html

  • Inside the command prompt, we are going to type this command:

    tasklist /m

    Type that into the black box and press enter. It will scroll down every program running and all the dll files that it has loaded.

  • To get a list of dll files loaded for a specific executable program, type this command:

    tasklist /m /fi “imagename eq [programname]"

    Replace [programname] with the name of the executable file you want to look up. For instance: tasklist /m /fi “imagename eq explorer.exe"


大数相乘

http://blog.csdn.net/hzgdiyer/article/details/6114420

我们知道计算机数据类型有int, long, char, float,double等等,还有指针是用来在内存中寻址的,在32bits系统中,指针是4个bytes(32 bit),即2的32次方等于4G,即32位的系统支持内存最大是4G,而我们目前的硬件CPU和操作系统(Win 7)支持64位寻址,也就是说指针占有8个bytes,大家想想2的64次方是多大。系统所支持的内存比4G大了很多很多很多倍,大家计算机系学习算法都知道用空间换时间,这下我们的内存足够大了,可以一下将所有的数据放入内存,提高运算效率。

64位的操作系统,C语言数据类型所占用最大8bytes(long), 范围[-2^32, 2^32-1], 最大值是:  9,223,372,036,854,775,807, 那么如果2^32乘以2^32,结果怎么样呢?如下:

Long la = 9,223,372,036,854,775,807;

Long lb = 9,223,372,036,854,775,807;

Long lresult = la * lb;

我们可以看到la * lb 结果肯定大于 2^32,我们用来存储计算结果的lresult 所占内存空间是8bytes, 根本放不下这个值,所以结算结果就会溢出。

我们可以用字符串来存储数据(任意长度的数据),即如果一个数据长度为100000,我们可以动态申请100000+1个长度char内存,即 char *p = new char[100001]; 

如下代码思路如下,我们运算的数据可以是正数(1111111),负数(-1111),也能是浮点数(-1.2222), 正数负数计算符号好说:2个运算数的符号相异或(XOR), 如果为1,计算结果就为负数。至于小数点,我们上小学时就学过了2个数相乘(1.11 * 2.22 ),步骤如下:

1.             先剔除小数点,再计算2数相乘,(111 * 222 = 24642)

2.             2个运算数的小数点位(倒数)相加 (2 + 2 = 4, 即1.11小数点位置2,  2,22小数点位置为2)

3.             相乘结果(24642) 倒数插入小数点位数之和(4)得到预算结果: 2.4642

 

整体思路如下:

1.             对输入的数据(字符串)提取 数字 + 符号 + 小数点位数,对应函数:

char *extract_string(char *sour, e_sign_type &sign, unsigned int &ndot)

2.             对提取出的 数字相乘,计算出结果;

char *mult_pos_int(char *mult1, char *mult2)

3.             对相乘结果,补上 符号 和 小数点位数

char *recover_string(char *sour, e_sign_type sign, unsigned int ndot)

 

        最后提供计算接口函数是:

char *mult_signed_num(char *mult1, char *mult2)

 

//代码如下,编译环境Visual c++ 2005,系统: windows Xp

 

#include “stdafx.h"

#include <string.h>

#include <iostream>

using namespace std;

 

enum e_sign_type

{

       ENUM_POSITIVE,      // 正数  

       ENUM_NEGATIVE,          // 负数

};

/*————————————————————————————–

Function:   2个字符串相乘

Parameter:  mult1: 乘数,mult2: 乘数

Return:     两数相乘的结果

Condition:  1. 这里假设这个数都是正整数,即不考虑小数点和负号

            2. 返回值的内存在这个函数里动态分配,注意在外部释放内存

——————————————————————————————*/

char *mult_pos_int(char *mult1, char *mult2)

{

              if  ( (NULL==mult1) && (NULL==mult2)  )

                     return NULL;

 

              unsigned int nlen1 = strlen(mult1);

              unsigned int nlen2 = strlen(mult2);

              // 本程序局限性:计算结果长度为:^32 = 4294967296,如果计算结果长度超过亿,将会溢出。

              // 不妨将类型修改为长度为bytes类型long long

              // 另外:nlen1+nlen2也可能溢出

              unsigned int nlen_r = nlen1+nlen2;  // 即数相乘的结果长度最大是乘数长度之和

              char *sz_res = new char[nlen_r+1];  // 最后还有一结束符

              if (NULL == sz_res)

              {     

                     cout << “new memory fail" << endl;

                     return NULL;

              }

              memset(sz_res, 0, nlen_r+1);

 

              char *end1 = mult1+nlen1-1;

              char *end2 = mult2+nlen2-1;

              char *end_r= sz_res+nlen_r-1;

              char *tok = end_r;

             

              int carry = 0;   // 进位

              while(mult1 <= end1)

              {

                     carry = 0;   // 进位

                     while (mult2 <= end2)

                     {

                            int tmp = (*end1-0x30) * (*end2-0x30) + carry + *end_r;

                            *end_r = tmp%10;

                            carry = tmp/10;

 

                            end_r–;

                            end2–;

                     }     

                    

                     *end_r = carry;       // high attention

 

                     end1–;

                     end2 = mult2+nlen2-1;

                     tok–;

                     end_r= tok;    // 每次运算完成后end_r后移一位

              }

 

 

              if (carry > 0)

              {

                     *sz_res = carry;   // 最高位为carry

                     char *pcur = sz_res;

                     for (unsigned int i=0; i<nlen_r; i++)   // high attention

                     {

                            *pcur += 0x30;

                            pcur++;

                     }

                     return sz_res;

              }

              else   // 最高位为,需要移位

              {

                     // 考虑到如果计算结果特别长,比如是sizeof(unsigned int),依次移位特别慢,

                     // 是否可以另外申请一块内存,用memcpy复制过去,代码如下:

                     char *sz_new = new char[nlen_r];  // 长度为nlen_r即可

                     memcpy(sz_new, sz_res+1, nlen_r);

 

                     delete []sz_res;

                     sz_res = NULL;

 

                     char *pcur = sz_new;

                     for (unsigned int i=0; i<nlen_r-1; i++)  // high attention: i<nlen_r-1

                     {

                            *pcur += 0x30;

                            pcur++;

                     }

                     return sz_new;

              }

}

 

/*————————————————————————————–

Function:   判断输入的字符串是否是浮点数

Parameter:  sz: input, s输入的字符串

Return:     0: 不是浮点数

                     其它值: 浮点数小数点所在字串的位置

Condition:  sz不为空

——————————————————————————————*/

int check_floating(char *sz)

{

       int npos = 0;

       char *end = sz + strlen(sz) – 1;

       while(sz < end)

       {

              if (‘.’ == *end)

                     return npos;

              else

                     end–;

 

              npos++;

       }

 

       return 0;

}

 

/*————————————————————————————–

Function:   从输入的字符串中提取数字信息,即剔除’-‘和’.’

Parameter:  sour:  输入的字符串

            sign: 传出的值,枚举

                     ndot:  传出的值, 0: 不是浮点数 其它值:小数点所在字符串的位置索引

Return:     剔除’-‘和’.’后的字符串

Notes:      返回的字符串内存是在这个函数内部分配的,需要在函数外部进行内存释放

——————————————————————————————*/

char *extract_string(char *sour, e_sign_type &sign, unsigned int &ndot)

{

        // 是否是负数的标示

       if (‘-‘ == *sour)

              sign = ENUM_NEGATIVE;

       else

              sign = ENUM_POSITIVE;

       // 乘数是否是浮点数的标志,ndot是小数点的位数

       ndot = check_floating(sour);     

 

       unsigned int nlen = strlen(sour);

 

       if (ENUM_NEGATIVE == sign)  // 判断是否有负号

              nlen–;

       if (ndot > 0)   // 判断是否是浮点数

              nlen–;

 

       // new memory

       char *sz_ret = new char[nlen+1];

       memset(sz_ret, 0,  nlen+1);

       char *cur = sz_ret;

       if (0 == ndot)

       {

              // 如果是负数,则’-‘号跳过

              if (ENUM_NEGATIVE == sign)

                     sour++;

              while (0 != *sour)

                     *cur++ = *sour++;

       }

       else

       {

              char *sz_inp = sour;

              if (ENUM_NEGATIVE == sign)

                     sz_inp++;

 

              while (0 != *sz_inp)

              {

                     if (‘.’ != *sz_inp)

                            *cur++ = *sz_inp++;

                     else

                            sz_inp++;

              }            

       }

 

       return sz_ret;

}

 

/*————————————————————————————–

Function:   给输入的字符串添加字符’-‘和’.’

Parameter:  sour:  输入的字符串

            sign:  传入的值,枚举

                     ndot:  传入的值, 0: 不是浮点数 其它值:小数点所在字符串的位置索引

Return:     添加’-‘和’.’后的字符串

Notes:      返回的字符串内存是在这个函数内部分配的,需要在函数外部进行内存释放

——————————————————————————————*/

char *recover_string(char *sour, e_sign_type sign, unsigned int ndot)

{

       int nlen = strlen(sour);

       if (ENUM_POSITIVE == sign)

              nlen++;     //如果是负数的话,长度加一,for ‘-‘

       if (ndot > 0)

              nlen++;    //如果浮点数的话,长度加一,for ‘.’

 

       char *sz_ret = new char[nlen+1];

       memset(sz_ret, 0, nlen+1);

 

       // 特殊情况: sour等于

       if (0 == atoi(sour))

       {

              *sz_ret = 0x30;

              return sz_ret;

       }

       else

       {

              char *ret_cur = sz_ret;

              if (ENUM_NEGATIVE == sign)

              {

                     *ret_cur = ‘-‘;

                     ret_cur++;

              }

              // 考虑小数点左边的整数

              int nlen_int = strlen(sour)-ndot;  // 整数长度

              char *sz_int = new char[nlen_int+1];

              memset(sz_int, 0, nlen_int+1);

              memcpy(sz_int, sour, nlen_int);

              if (0 == atoi(sz_int))   // 整数部分全部为

              {

                     *ret_cur = 0x30;

                     ret_cur++;

              }

              else

              {

                     int num = 0;  // 即无用的个数,比如: 00011,即num = 3

                     char *cur = sz_int;

                     while(cur < sz_int+nlen_int)

                     {

                            if (0x30 == *cur)

                            {

                                   cur++;

                                   num++;

                            }

                            else

                                   break;

                     }

 

                     memcpy(ret_cur, sour+num, nlen_int-num);

                     ret_cur += (nlen_int-num);

              }

              delete []sz_int;

              sz_int = NULL;

 

              // 考虑小数部分, ndot即为小数部分的长度

              if (ndot > 0)

              {

                     char *pdeci = sour+strlen(sour)-ndot;

                     if (0 == atoi(pdeci))

                     {//do nothing

                     }

                     else

                     {

                            // 处理小数点

                            *ret_cur = ‘.’;

                            ret_cur++;

 

                            int num = 0; // 小数位无效的个数,比如:.11000,即num为

                            char *end = sour+strlen(sour)-1;

                            while (pdeci < end)

                            {

                                   if (0x30 == *end)

                                   {

                                          end–;

                                          num++;

                                   }

                                   else

                                          break;

                            }

 

                            memcpy(ret_cur, pdeci, ndot-num);

                     }

                     }

              }

 

              return sz_ret;

       }

 

/*————————————————————————————–

Function:   2个字符串相乘

Parameter:  mult1: 乘数,mult2: 乘数

Return:     两数相乘的结果

Condition:  1. 这个数可以是有符号的,也可以是浮点数

            2. 返回值的内存在这个函数里动态分配,注意在外部释放内存

——————————————————————————————*/

char *mult_signed_num(char *mult1, char *mult2)

{

       if  ((NULL==mult1) && (NULL==mult2))

              return NULL;

 

       e_sign_type sign1 = ENUM_POSITIVE;     // 乘数是否是负数的标示

       e_sign_type sign2 = ENUM_POSITIVE;

       unsigned int ndot1 = 0;      // 乘数是否是浮点数的标志,ndot是小数点的位数

       unsigned int ndot2 = 0;

 

       char *sz_para1 = extract_string(mult1, sign1, ndot1);

       char *sz_para2 = extract_string(mult2, sign2, ndot2);    

       char *sz_res = mult_pos_int(sz_para1, sz_para2);

 

       if (NULL != sz_para1)

       {

              delete []sz_para1;

              sz_para1 = NULL;

       }

       if (NULL != sz_para2)

       {

              delete []sz_para2;

              sz_para2 = NULL;

       }

 

       char *sz_val = recover_string( sz_res,

                                                           (sign1==sign2) ? ENUM_POSITIVE : ENUM_NEGATIVE,

                                                           ndot1+ndot2);

 

       if (NULL != sz_res)

       {

              delete []sz_res;

              sz_res = NULL;

       }

 

       return sz_val;

}

 

int _tmain(int argc, _TCHAR* argv[])

{

              char sz1[256] = {0};

              cout << “pls enter num1″ << endl;

              cin >> sz1;

 

              char sz2[256] = {0};

              cout << “pls enter num2″ << endl;

              cin >> sz2;

 

              char *sz_res = mult_signed_num(sz1, sz2);

              cout << “num1 * num2 = " << endl;

              cout << sz_res << endl;

              if (NULL != sz_res)

              {

                     delete sz_res;

                     sz_res = NULL;

              }

      

              return 0;

}


Clock Speed: Tell Me When it Hertz

Clock Speed: Tell Me When it Hertz


Pushing the Limits of Windows: Processes and Threads

Pushing the Limits of Windows: Processes and Threads


Trip over threads to trap multicore bugs

Trip over threads to trap multicore bugs

To debug multi-threads is difficult to reproduce because of unpredictable OS scheduling.

There is some way to put a layer over OS scheduler to monitor and control self threads exec combinations.

In this way, you can easily know which combination will reproduce your bug and save more time.


Google I/O 2009 – V8: ..High Performance JavaScript Engine