• 2011-06-24

    关系数据库应用设计基础

    Views: 27445 | 1 Comment

    这是我给部门同事做的技术分享.

    当今绝大部分的软件系统都用到了关系数据库, 所以, 作为软件开发工程师, 必须掌握关系数据库应用设计能力.

    Posted by ideawu at 2011-06-24 18:02:57 Tags:
  • 2011-03-31

    史上最强大的PHP Web面试题(会做就能进百度)

    Views: 53571 | 58 Comments

    注: 只要你会做了这道题目, 你的能力已经可以进入百度了! 如果别的部门不要你, 请你给我发邮件, 我一定尽我所能强烈推荐你! 如果你不想加入百度, 而别的公司又不要你, 只能说明那家公司瞎眼了.

    题目: 见图片, 该图是某网页的一个区域的截图, 用于显示商品或者其它信息的分类. 该分类的每一项可以折叠和收起(展开和收缩, 如果有子分类的话). 分类的级数不固定. 现有一个PHP变量:

    $cats = array(
        array(
            'id' => 1,
            'name' => '学术和教育',
            'children' => array(
                array(
                    'id' => 2,
                    'name' => '自然科学',
                    'children' => null,
                ),
                // ...
            ),
        ),
        // ...
    );
    

    请写一段PHP代码, 将该数组所包含的分类数据生成一段能实现如图片所示功能的HTML/JavaScript代码, 可不考虑CSS样式.

    ----------

    注解: 这道题目考察的范围非常广, 包括PHP, HTML, JavaScript, CSS, 递归, 只有真正掌握了如上几种全部技能, 才能实现完整的功能, 否则必须依赖分工. 应聘者所能实现的程度越大, 得分就越高.

    如果应聘者的应聘职位不包括HTML/JS/CSS, 那么题目可改为: 把上面的PHP数据用缩进换行文本的形式保存到文件, 并读取文件生成一个同样的PHP数组.(自定义格式的序列化和反序列化)

    看到这篇日志的读者, 如果已经做了出来, 并且个人想加入百度, 请在评论中回复URL并说明你的意愿, 我会主动联系你. 或者你可以把程序打包发给我.

    Continue reading »

    Posted by ideawu at 2011-03-31 16:57:24 Tags:
  • 2011-02-17

    主要排序算法的比较(精炼)

    Views: 8655 | No Comments

    来自: Wikipedia

    Heapsort primarily competes with quicksort, another very efficient general purpose nearly-in-place comparison-based sort algorithm.

    Quicksort is typically somewhat faster, due to better cache behavior and other factors, but the worst-case running time for quicksort is O(n2), which is unacceptable for large data sets and can be deliberately triggered given enough knowledge of the implementation, creating a security risk. See quicksort for a detailed discussion of this problem, and possible solutions.

    Thus, because of the O(n log n) upper bound on heapsort's running time and constant upper bound on its auxiliary storage, embedded systems with real-time constraints or systems concerned with security often use heapsort.

    Heapsort also competes with merge sort, which has the same time bounds, but requires Ω(n) auxiliary space, whereas heapsort requires only a constant amount. Heapsort also typically runs more quickly in practice on machines with small or slow data caches. On the other hand, merge sort has several advantages over heapsort:

    • Like quicksort, merge sort on arrays has considerably better data cache performance, often outperforming heapsort on a modern desktop PC, because it accesses the elements in order.
    • Merge sort is a stable sort.
    • Merge sort parallelizes better; the most trivial way of parallelizing merge sort achieves close to linear speedup, while there is no obvious way to parallelize heapsort at all.
    • Merge sort can be easily adapted to operate on linked lists (with O(1) extra space[7]) and very large lists stored on slow-to-access media such as disk storage or network attached storage. Heapsort relies strongly on random access, and its poor locality of reference makes it very slow on media with long access times. (Note: Heapsort can also be applied to doubly linked lists with only O(1) extra space overhead)

    Introsort is an interesting alternative to heapsort that combines quicksort and heapsort to retain advantages of both: worst case speed of heapsort and average speed of quicksort.

    Posted by ideawu at 2011-02-17 16:57:21
  • 2010-09-22

    以浏览器为核心的客户端软件的安全问题

    Views: 8484 | No Comments

    以浏览器为核心的客户端软件具有开发快速, 并且能使用浏览器的各种特性(如js脚本, flash插件等), 所以越来越多的客户端软件开始应用浏览器作为软件的界面渲染引擎.

    但是, 浏览器也是安全问题最多的软件之一. 因其应用广泛, 导致攻击方法层出不穷. 前段时间, QQ客户端的某个版本就遇到了这个问题. 这个版本的QQ使用IE作为聊天记录的界面引擎, 似乎由于疏忽的原因, 没有对聊天信息中的HTML标签进行过滤, 导致用户可以通过在聊天信息中包含JavaScript脚本, 从而在对方机器上执行.

    例如:

    <script type="text/javascript">alert('hahaha');</script>
    

    用户打开聊天历史记录时, 便会弹出一个窗口, 显示"hahaha". 还有嵌入iframe的:

    <iframe src="http://some" width="100%" height="400"></iframe>
    

    这样, 用户在打开聊天历史记录时, 却看到了一个网页, 而这个网页可能是挂马的.

    所以, 使用浏览器为核心的客户端软件, 必须重视安全问题, 要对发给浏览器渲染的所有字符进行过滤. 最好的方法是使用一种模板语言, 简单的如ubb, 而不是直接使用HTML.

    Posted by ideawu at 2010-09-22 11:19:39
  • 2010-09-09

    没见过比svn更难用的工具

    Views: 10545 | 3 Comments

    我的需求很简单, diff 某个版本和我当前的代码, 正常应该是

    svn diff url_xxx .(这样操作方式和diff命令一致)

    url_xxx 就是那个版本的路径, 点号"."就是当前目录, 没想到竟然不行! 太弱智的东西了! 真正的用法是:

    svn diff --new url_xxx --old .(这样不对, 因为顺序弄反了!)

    正确的是

    svn diff --old url_xxx --new .

    svn 从来就是这么弱智, 比如这一篇文章: 请提供Fuck-All选项

    Posted by ideawu at 2010-09-09 13:35:12
  • 2010-08-29

    Lighttpd mod_fastcgi源码分析

    Views: 21825 | No Comments

    最近在设计一种网络服务器架构, 最重要的一点是把耗时操作委托给工作进程(或者线程)来做, 所以考察一下 fastcgi. 大概看了下 lighttpd 的 mod_fastcgi 的源码, 没想到立即被卡住了. 根据我的想法, PHP 等 fastcgi 程序(php-cgi 进程)监听网络, 然后 mod_fastcgi 只需要 connect 这些进程即可, 奇怪的是, 我竟然看到了 listen! -

    fcgi_spawn_connection() 函数:
    
    fcgi_fd = socket(socket_type, SOCK_STREAM, 0);
    
    if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
        close(fcgi_fd);
        fcgi_fd = socket(socket_type, SOCK_STREAM, 0);
        /* create socket */
        bind(fcgi_fd, fcgi_addr, servlen);
        listen(fcgi_fd, 1024);
    
        switch ((child = fork())) {
        case 0: {
            // child process
            if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
                close(FCGI_LISTENSOCK_FILENO);
                dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
                close(fcgi_fd);
            }
            /* exec the cgi */
            execve(arg.ptr[0], arg.ptr, env.ptr);
            exit(errno);
        }
    }
    

    我很奇怪, mod_fastcgi 为什么要监听网络连接? 谁会连接它? 问了同事, 同事说可能是 fastcgi 进程要连接它, 可问题是 fastcgi 进程怎么知道连接什么地方, 更不用说, fastcgi 协议里没有提到要 fastcgi 进程主动连接 Web Server 一说.

    Continue reading »

    Posted by ideawu at 2010-08-29 18:00:51
|<<<2345678910>>>| 6/11 Pages, 61 Results.