A crazy guy
  • 学习C语言

    C语言,一门系统级语言,虽然现在很多应用层很少用到它,但学习一下C语言有利于更好的了解系统底层

    任何语言的开端都从Hello World开始,新建一个hello.c并写入以下代码

    #include <stdio.h>
    
    int main() {
      printf("Hello world");
      return 0;
    }
    

    源码写完了,下一步是需要编译

    [root@test01 learn]# gcc hello.c 
    

    编译结束后会在目录下生成a.out编译文件

    [root@test01 learn]# ll
    total 16
    -rwxr-xr-x 1 root root 8440 Oct 10 16:45 a.out
    -rw-r--r-- 1 root root   72 Oct 10 16:45 hello.c
    

    ...

    READ ALL

  • IE6通过class动态切换样式无效解决方法

    美工那边给了一个焦点图的样式

    full

    当图片切换的时候,底部小白点的样式要相应变化,美工写好了样式,直接在白点element上添加class=ok就好。

    但在IE6下不起作用,通过工具查看,发现样式class属性已改写成功,但小白点的样式就是不变化。

    后来直接用JavaScript在标签inline-style方式写样式,而不是通过class切换修改样式,问题解决了!

    ...

    READ ALL

  • 博文分页实现

    通常我们在浏览新闻时发现有些新闻内容有分页功能,这些分页是怎么实现的呢?对于存在数据库里的文章内容,并没有没有分页概念或者功能,只能在写文章时通过一些技巧去实现。

    目前分页多半是按照两种方式:

    根据字节长度来实现分页

    比如,文章有三千个字符,我每一页显示一千个字符,那么可以分三页。这种方式只能适用于纯文字的文章。否则如果有标签被拆开,就会影响页面美观了。比如你正好有一个标签<img src="img.jpg" />这样一个标签,但是第一页的长度截取只截取到了<im,剩下的g src="img.jpg" />被分割到了下一页,其实这种方式也可以处理,即判断是不是标签被断开?如果断开就递归处理耦合就好,第二页的开头也需要这么处理,但比较麻烦。

    ...

    READ ALL

  • 什么是EOF?

    它是end of file的缩写,表示"文字流"(stream)的结尾。这里的"文字流",可以是文件(file),也可以是标准输入(stdin)。

    但程序里为了判断EOF通常都定义了函数或者变量,比如C语言里可以这样来判断字符是不是等于EOF

    if (getchar() == EOF) {
      printf("It's end of file");
    }
    

    这个EOF是定义在stdio.h里的常量,通常是-1,因为文本对应的ASCII码都是正值,不可能有负值。

    但是正常的文件读取到末尾就会遇到EOF从而结束读取,如这段代码

    int c;
    
    while ((c = getchar()) != EOF) {
      putchar(c);
    }
    
    printf("Read end");
    

    ...

    READ ALL

  • Zencart后台顶部提示框问题解决

    一步步按照教程来操作,登录后台后页面顶部总是提示提示

    full

    教程里没有这个问题的解答方式,网上搜索也没有,仔细研究半天后才发现这是一个权限问题。

    默认我们运行PHP以及WebServer程序总是创建www用户,组也是www,比如我的环境就是。而我们上传程序的时候往往是以root或者其它非www用户上传,导致PHP程序执行权限问题而无法写或者创建一些文件。

    解决方法,项目下所有文件所有者、组都更改为你环境里运行PHP,WebServer得用户,比如我的可以这么解决

    ...

    READ ALL

  • Linux如何查看CPU信息

    使用lscpu命令

    [root@Docker ~]# lscpu
    Architecture:          x86_64
    CPU op-mode(s):        32-bit, 64-bit
    Byte Order:            Little Endian
    CPU(s):                4
    On-line CPU(s) list:   0-3
    Thread(s) per core:    2
    Core(s) per socket:    2
    Socket(s):             1
    NUMA node(s):          1
    Vendor ID:             GenuineIntel
    CPU family:            6
    Model:                 85
    Model name:            Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
    Stepping:              4
    CPU MHz:               2499.980
    BogoMIPS:              4999.96
    Hypervisor vendor:     KVM
    Virtualization type:   full
    L1d cache:             32K
    L1i cache:             32K
    L2 cache:              1024K
    L3 cache:              33792K
    NUMA node0 CPU(s):     0-3
    

    直接查看文件

    [root@vultr ~]# cat /proc/cpuinfo
    processor       : 0
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 85
    model name      : Virtual CPU 82d9ed4018dd
    stepping        : 4
    microcode       : 0x1
    cpu MHz         : 2600.000
    cache size      : 16384 KB
    physical id     : 0
    siblings        : 1
    core id         : 0
    cpu cores       : 1
    apicid          : 0
    initial apicid  : 0
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 13
    wp              : yes
    bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass
    bogomips        : 5200.00
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 40 bits physical, 48 bits virtual
    power management:
    

    ...

    READ ALL

  • 阿里云双十一团购我获得了十一个月延长期

    说实话,我感觉动作还是慢了点。当倒计时到零的时候突然又变成另外一个倒计时,我误以为没开始,直到最后确定为活动开始以后才点提交订单。

    结果,我排到了第三档!

    我支付的时间是零一分三十秒,在结果没出来之前,我以为最坏的结果也是第二档内,即111位以内。下次,得眼疾手快了!

    full

    总共支付了870元,获得了23个月的服务器,算下来每个月38元左右。相当便宜了,特别是相对于国内。

    ...

    READ ALL

  • Linux使用ntpdate同步时间

    Linux里要同步时间特别简单,使用utpdate命令就可以

    CentOS可以

    yum install utpdate
    

    Ubuntu可以

    sudo apt-get install ntp
    

    同步时间

    ntpdate -u time.windows.com
    

    常用的服务器列表有以下

    • 210.72.145.44 (国家授时中心服务器IP地址)
    • ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
    • s1a.time.edu.cn 北京邮电大学
    • s1b.time.edu.cn 清华大学
    • s1c.time.edu.cn 北京大学
    • s1d.time.edu.cn 东南大学
    • s1e.time.edu.cn 清华大学
    • s2a.time.edu.cn 清华大学
    • s2b.time.edu.cn 清华大学
    • s2c.time.edu.cn 北京邮电大学
    • s2d.time.edu.cn 西南地区网络中心
    • s2e.time.edu.cn 西北地区网络中心
    • s2f.time.edu.cn 东北地区网络中心
    • s2g.time.edu.cn 华东南地区网络中心
    • s2h.time.edu.cn 四川大学网络管理中心
    • s2j.time.edu.cn 大连理工大学网络中心
    • s2k.time.edu.cn CERNET桂林主节点
    • s2m.time.edu.cn 北京大学

    ...

    READ ALL

  • JavaScript日期时间类型(Y-m-d H:i:s)与时间戳互转

    JavaScript中没有类似PHP那样简便的函数可以直接将时间戳与日期类型格式相互转换,于是只好自己写一个函数,使用时方便调用。

    function datetime_to_unix(datetime){
      var tmp_datetime = datetime.replace(/:/g,'-');
      tmp_datetime = tmp_datetime.replace(/ /g,'-');
      var arr = tmp_datetime.split('-');
      var now = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
      return parseInt(now.getTime()/1000);
    }
    
    function fillZero(num) {
      return num >= 10 ? num : '0' + String(num)
    }
     
    function unix_to_datetime(unix) {
      var now = new Date(parseInt(unix) * 1000);
      return [
        [
          now.getFullYear(),
          fillZero(now.getMonth() + 1),
          fillZero(now.getDate())
        ].join('-'),
        [
          fillZero(now.getHours()),
          fillZero(now.getMinutes()),
          fillZero(now.getSeconds())
        ].join(':'),
      ].join(' ')
    }
     
    var datetime = '2012-11-16 10:36:50';
    var unix = datetime_to_unix(datetime);
    console.log(datetime + ' 转换后的时间戳为: ' + unix);
     
    var unix = 1353033300;
    var datetime = unix_to_datetime(unix);
    console.log(unix + ' 转换后的日期为: ' + datetime);
    

    ...

    READ ALL

  • 解决IE8版本以下不支持HTML5标签

    HTML5新增不少比较有意思的标签,主流浏览器都支持了,包括IE9,10。

    然而IE8或以下版本不支持HTML5新增标签,导致HTML5构造页面在IE8或以下显示页面混乱出错,为了兼容IE8或以下IE浏览器支持HTML5标签,我们可以这么解决

    下载html5shiv.js

    页面引入html5shiv.js

    <script src="html5shiv.js"></script>
    

    并且对HTML标签声明样式

    section,
    article,
    aside,
    header,
    footer,
    nav,
    dialog,
    figure {
      display:block;
    }
    

    ...

    READ ALL