• 一次愚蠢的firebug调试经历

    之前在firebug下打断点刷新后一直都挺好用,后来又一次不知道怎么了就一直都刷新后断点记录全消失,这点让我很郁闷。于是每次为了断点都需要把页面默认执行的函数停止,然后等进入页面后再找到要断点的地方,再手动执行断点代码处实在累人。并且换了重装firebug、换台电脑都一样,甚至一度怀疑哪里没设置好导致的,为防止以后调试麻烦决定解决下这个问题。

    一开始的思路是在网络上搜索“Firebug断点 刷新消失”居然没有找到任何疑似记录,以为关键字不准确,再缩小为:“Firebug断点”,文章一大堆,并且文章上面都明确指明刷新后断点记录不会消失。。。没辙了!

    ...

    READ ALL

  • 一个纯CSS实现的分类菜单

    动手写了一个纯CSS的分类菜单,貌似还挺好用,可惜就没有添加动态效果了

    full

    点这里看Demo

    index.html

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8" />
        <title>分类菜单</title>
        <style type="text/css">
          * {
            margin: 0; 
            padding: 0;
          }
    
          body {
            font: 14px/1.5 "宋体";
          }
    
          a {
            text-decoration: none; 
          }
    
          a:hover {
            color: red; 
          }
    
          ul {
            position: relative; 
            margin: 50px 0 0 50px;
            width: 300px;
            border: 2px solid #aa9900;
          }
    
          li {
            height: 30px; 
            line-height: 30px;
            width: 100%;
            text-indent: 1em;
            list-style: none;
            border-top: 1px solid #CCC;
          }
    
          li:hover,
          li:hover + li,
          li:first-child {
            border-top: none; 
            height: 31px;
            line-height: 31px;
          }
    
          div.box {
            width: 300px; 
            height: calc(100% + 2px);
            display: none;
            left: 300px;
            top: -2px;
    
            border: 1px solid #999;
            position: absolute;
            z-index: 1;
    
            background: #EEE;
          }
    
          div.item {
            position: relative; 
            width: 100%;
            height: 100%;
          }
    
          li:hover div.box {
            display: block;
          }
    
          li div.item span.link { 
            display: block;
            width: calc(100% - 1px);
            height: calc(100% - 2px);
            position: absolute;
            left: 0;
            top: 0;
            border-style: solid;
            border-color: #FFF;
            border-width: 1px 0 1px 1px;
            z-index: 2;
          }
    
          li:hover div.item span.link {
            border-color: #999;
            background: #EEE;
            width: 100%;
          }
    
          span.icon {
            position: absolute;
            right: 10px;
            top: 0;
            color: #999;
            font-weight: bold;
            font-family: serif;
          }
    
          li:hover a {
            color: #270; 
          }
    
        </style>
      </head>
      <body>
        <ul>
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类1</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类1 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类2</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类2 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类3</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类3 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类4</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类4 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类5</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类5 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类6</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类6 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类7</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类7 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类8</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类8 详细信息</div>
          </li> 
    
          <li>
            <div class="item">
              <span class="link">
                <a href="#">分类9</a> 
              </span>
              <span class="icon">&gt;</span>
            </div>
            <div class="box">分类9 详细信息</div>
          </li> 
        </ul> 
      </body>
    </html>
    

    ...

    READ ALL

  • CSS inline-block后有换行符变成空白间隔bug

    以前都使用display: block很少使用display: inline-block,近期写样式有时候为了方便我也使用inline-block,之后发现有问题,每个元素之间多了一个空白

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8" /> 
        <style type="text/css"> 
          * {
            margin: 0; 
            padding: 0;
          }
    
          span {
            margin: 0; 
            padding: 0;
            display: inline-block;
            width: 50px;
            height: 20px;
            background: red;
          } 
        </style>
      </head>
      <body>
        <span></span>
        <span></span>  
        <span></span> 
        <span></span> 
      </body>
    </html>
    

    ...

    READ ALL

  • Java字符串与数字互转

    字符串转数字

    String s = "8532";
    
    short t = Short.parseShort(s);
    int i = Integer.parseInt(s);
    long l = Long.parseLong(s);
    Float f = Float.parseFloat(s);
    Double d = Double.parseDouble(s);
    

    如果字符串转换不成功会抛出一个运行时错误,需要注意一下

    数字转字符串

    // 其中 something 为任意一种数字类型
    String s = String.valueOf(something);
    
    // 如果确保 something 不会为null
    String s = something.toString();
    
    // 还有一种
    String s = something + "";
    

    ...

    READ ALL

  • Nginx 403 Forbidden 问题

    今天在一个新的环境上安装Nginx,结果访问的都是403

    full

    通常显示403我立马都会想到路径配置不对,但我仔细看了一下,目录路径没问题

    nginx.conf

    server {
      listen       80;
      server_name  localhost;
    
      #charset koi8-r;
    
      #access_log  logs/host.access.log  main;
    
      location / {
        root   /root/html;
        index  index.html index.htm;
      }
    }
    

    ...

    READ ALL

  • cwRsync命令行带密码

    full

    cwRsync是基于Win平台的rsync解决方法,但经过测试有一个选项参数--password-file始终都不起作用

    @ECHO OFF
    D:
    cd "\Program Files (x86)\cwRsync\bin"
    rsync ^
    -vzrtopg ^
    --progress ^
    --delete ^
    /cygdrive/d/Workspace/Aptana/demo/ ^
    user@192.168.1.48::demo ^
    --port=7876 ^
    --password-file=/cygdrive/d/Workspace/Aptana/demo/rsyncd/passwd.txt ^
    --exclude-from=/cygdrive/d/Workspace/Aptana/demo/rsyncd/filter.txt
    pause
    

    ...

    READ ALL

  • MySQLdb ImportError libmysqlclient.so.18

    安装MySQLdb后,导入包时MySQLdb出错如下

    [root@lizhong MySQL-python-1.2.3]# /usr/local/bin/python2.7
    Python 2.7.6 (default, Apr 10 2014, 15:45:39) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /soft/MySQL-python-1.2.3 is being added to sys.path
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "MySQLdb/__init__.py", line 19, in <module>
        import _mysql
      File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>
      File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
    ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or direc
    

    ...

    READ ALL

  • 关于Linux动态链接so文件

    在Linux下写C程序时,常常有很多基础通用重复性的代码,最常见的比如重复使用CURL库创建HTTP请求,动态链接库就为了解决这个问题,可以把重复性的函数库单独编译成so文件,然后多个程序可以共享一个so文件提供的函数库

    Linux内置了一些常见的类库so文件,我们也可以自己编译自己需要的类库文件放到/usr/lib目录下,使用动态链接库有以下优势

    • 提升编译速度,类库部分不需要重新编译
    • 更容易升级部分功能,比如所有程序依赖curl库,那么如果curl可以单独升级而不用重新编译程序
    • 由于源码体积减少,所以编译出来的可执行文件体积也小

    ...

    READ ALL

  • Nginx定义404页面

    前几天,一朋友出程序出问题却怎么查都没看出问题,于是让我帮它看看。其实它是Ajax请求了很多个模板,然后把模板写到页面中。关键是所有请求的页面都是200正常状态码返回,表面上看没什么问题,实际上有些请求虽然返回200状态码,但给回的状态码是200。WebServer是Nginx,我觉得有可能配置了Nginx的404错误页面,虽然请求不存在的资源可以成功返回404页面,但返回状态码确是200。

    404.html

    This is 404 page.
    

    请求一个不存在的页面:

    full

    ...

    READ ALL

  • Django自带加密模块的使用

    在Win平台开发Python项目往往因为加密模块不能使用crypt加密模块而感到蛋疼,这次使用Django在Win平台开发项目就又为这个加密模块而发愁。但考虑到Django有用户验证模块,证明它已具备跨平台的加密模块。于是阅读文档,在https://docs.djangoproject.com/en/1.6/topics/auth/passwords/页面发现有这样一段话

    Manually managing a user’s password
    The django.contrib.auth.hashers module provides a set of functions to create and validate hashed password. You can use them independently from the User model.
    check_password(password, encoded)
    If you’d like to manually authenticate a user by comparing a plain-text password to the hashed password in the database, use the convenience function check_password(). It takes two arguments: the plain-text password to check, and the full value of a user’s password field in the database to check against, and returns True if they match, False otherwise. Changed in Django 1.6:
    In Django 1.4 and 1.5, a blank string was unintentionally considered to be an unusable password, resulting in this method returningFalse for such a password.
    make_password(password[, salt, hashers])
    Creates a hashed password in the format used by this application. It takes one mandatory argument: the password in plain-text. Optionally, you can provide a salt and a hashing algorithm to use, if you don’t want to use the defaults (first entry of PASSWORD_HASHERS setting). Currently supported algorithms are: 'pbkdf2_sha256', 'pbkdf2_sha1', 'bcrypt_sha256'(see Using bcrypt with Django), 'bcrypt', 'sha1', 'md5', 'unsalted_md5' (only for backward compatibility) and 'crypt' if you have the crypt library installed. If the password argument is None, an unusable password is returned (a one that will be never accepted by check_password()).

    ...

    READ ALL