1. algorithm

    螺旋矩阵
    很久之前做”数组和字符串”探索时的问题. 当时只顾写一个复杂的循环解决问题, 没有拆分, 导致越写越烦躁, 然后放下了很久. 这次把数组分层, 然后每次都剥离一层然后重组连接到目的数组, 按部就班.

    1. /**
    2. * Note: The returned array must be malloced, assume caller calls free().
    3. */
    4. int *build(int **matrix, int matrixSize, int matrixColSize, int **ret, int x, int y)
    5. {
    6. int *p = *ret;
    7. int i = 0;
    8. for(; i < matrixColSize; i++) {
    9. *p++ = matrix[0 + x][i + y];
    10. }
    11. for(i = 1; i < matrixSize; i++) {
    12. *p++ = matrix[i + x][matrixColSize - 1 + y];
    13. }
    14. --matrixSize;
    15. --matrixColSize;
    16. if(matrixSize == 0 || matrixColSize == 0) {
    17. return NULL;
    18. }
    19. for(i = matrixColSize - 1; i >= 0; i--) {
    20. *p++ = matrix[matrixSize + x][i + y];
    21. }
    22. for(i = matrixSize - 1; i > 0; i--) {
    23. *p++ = matrix[i + x][0 + y];
    24. }
    25. return p;
    26. }
    27. int* spiralOrder(int** matrix, int matrixSize, int* matrixColSize, int* returnSize){
    28. if(matrixSize == 0 || matrixColSize == 0) {
    29. *returnSize = 0;
    30. return NULL;
    31. }
    32. *returnSize = *matrixColSize * matrixSize;
    33. int *ret = malloc(sizeof(int) * (*returnSize));
    34. int *status = ret;
    35. int x = 0;
    36. int y = 0;
    37. do {
    38. status = build(matrix, matrixSize, *matrixColSize, &status, x, y);
    39. ++x;
    40. ++y;
    41. matrixSize -= 2;
    42. *matrixColSize -= 2;
    43. if(matrixSize <= 0 || *matrixColSize <= 0)
    44. break;
    45. }while(status);
    46. return ret;
    47. }

    中间在转移目标的int**时出现一些小问题:

    int **matrix;
    matrix = &(&(matrix[1][1]));
    
    lvalue required as unary ‘&’ operand
    

    我的分析是这样的:
    不能这么简单粗暴的转移matrix, 因为matrix[1][1]虽然作为一个值是有地址的, 但是再一次取地址作为一个行指针时, 地址在地址列表中是没有映射的, 导致问题.

    1. review

    Don’t be a one trick pony
    Learning a new programming language isn’t difficult, it just takes time, and ideally a non-trivial project to work on to turn theory into practice. I think companies should offer this to their developers as part of their career development. It’s time we concentrated more on good software engineering and less on defending our choice of programming language.
    现在一直觉得写代码就像写作文, 各种编程语言就像现实生活中交流的语言. 每一种语言都是一个建模过程的体现. 我相信所有问题都可以被任意一种语言解决, 只是翻译的过程损耗不同而已. 就像我可以巧妙地用一首五言古诗反应我现在的心情, 也可以用三句俳句, 抑或更加简单的一个成语概括, 最最不济我还可以讲一个故事. 但是这些的本质都是表达我的观点, 表现我的心情.
    技术的本质是高效的解决问题, 提升效率, 语言和框架都是工具包. 没有什么人单凭一个锤子能做好木工, 除非他看到什么都是钉子.

    1. tips

    ntpclient 命令, openwrt中同步时间:
    Usage: ntpclient [-c count] [-d] [-f frequency] [-g goodness] -h hostname
    [-i interval] [-l] [-p port] [-q min_delay] [-r] [-s] [-t]

    example:
    ntpclient -i 300 -s -l -D -p 123 -h ntp1.aliyun.com
    其中:
    -i 间隔时间 每隔一定时间检查时间(默认值为600)
    -l 尝试服务器使用adjtimex锁定本地时钟(2) (L)
    -c count count时间计数后停止(默认为0意味直到永远)
    -s 简单的时钟设置(相当于-c 1)
    -p 端口名 锁定本地NTP客户端UDP端口(默认为0表示“任何可用的”)
    -h 主机名(ip地址)(强制)NTP服务器,对系统时间来衡量
    -D 后台运行 daemon

    adjtimex

    1. share

    https://github.com/alibaba/spring-cloud-alibaba
    一个java语言的微服务架构项目, 可能会是高并发和大数据访问量方案一个不错的选择.