Intelligence without ambition is a bird without wings.

2015-06-26
UUID

含义

通用唯一识别码 (Universally Unique Identifier)

作用

是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定

表示方法

  • 标准 4B-2B-2B-2B-6B(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  • 微软(GUID) 4B-2B-2B-8B(xxxxxxxx-xxxx- xxxx-xxxxxxxxxxxxxxxx)

原理

MAC地址:故意情况下可重复;
机器标识:Java下就是JVM标识,故意情况下可重复;
纳秒级当前时间:故意情况下可重复;
随机数:小概率重复;
自增序列数(或时钟序列):循环溢出时重复;

阅读此文

2015-06-26
mysq-hex与unhex

功能

  • hex

    字符串转换为对应的ASCII码的16进制字符串

    数字转换为16进制字符串

  • unhex

    将16进制数转换为字符串

阅读此文

2015-06-26
arch-安装yaourt

  1. 添加源仓库到pacman

    vi /etc/pacman.conf
    
    [archlinuxfr]
    SigLevel = Never
    Server = http://repo.archlinux.fr/$arch
    
  2. 更新安装

    pacman -Sy yaourt
    
  3. 安装拓展

    yaourt -S aurvote customizepkg rsync
    
阅读此文

2015-06-26
arch-将吃豆人放入pacman

  1. vi /etc/pacman.conf

    # Misc options
    Color
    ILoveCandy
    
阅读此文

2015-06-25
mysq-常用语句

  • 获取排序中指定序号列

    SELECT stockid, close/10000, pctchg/100, transday FROM stock_app.t_k_line_day WHERE stockid=? ORDER BY transday DESC LIMIT 1,1
    
  • mysql下使用update set from select

    UPDATE friends INNER JOIN users ON friends.friendid=users.userid 
    SET friends.friendname=users.username
    
  • 判断等于NULL

    is NULL
    
  • 取指定数目数据

    select transday,preclose from t_k_line_day where '601866.SH' = stockid order by transday desc limit 10;
    
  • 修改列名和定义

    alter table t_day_recommand change column proce price selectprice int(11);
    
  • 修改列定义

    alter table t_day_recommand modify column inperiod int(11) DEFAULT NULL AFTER period;
    
  • 添加列

    alter table t_product add column `issue_index` bigint NOT NULL COMMENT '发行点数, 用来计算份数' after issue_time;
    
  • 命令行执行sql

    mysql -e "select * ...."
    
  • 选择最大值,作为某个比较条件!

    select a.period, a.stockid, b.stockname, c.preclose, 
        (select count(userid) as count from t_follow_buy where stockid = a.stockid and status = 1) as followcount, 
        (a.highestprice - a.selectprice) / a.selectprice as maxincrease
        from stock_app.t_day_recommand a, stock_app.t_stock_base b, stock_app.t_realtime_quotation c 
        where a.priority = 0 and a.stockid = b.stockid and a.stockid = c.stockid and a.period = (select max(period) from t_day_recommand)
        ;
    
  • update select

    UPDATE table1 alias
    SET (column_name,column_name ) = (
    SELECT (column_name, column_name)
    FROM table2
    WHERE column_name = alias.column_name)
    WHERE column_name = VALUE
    
  • update table by select

    UPDATE table1 dest, (SELECT * FROM table2 where id=x) src 
    SET dest.col1 = src.col1 where dest.id=x ;
    
  • Insert to table or update if exists

    INSERT INTO table (id, name, age) VALUES(1, "A", 19) ON DUPLICATE KEY UPDATE    
    name=VALUES(name), age=VALUES(age)
    
    1. http://stackoverflow.com/questions/4205181/insert-to-table-or-update-if-exists-mysql
    2. http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html
  • 查看mysql用户登录

    select host,user from mysql.user;
    
  • 获取最近天的数据

    SELECT *
    FROM t_k_line_minute
    WHERE stockid="000300.SH" AND DATE(transminute) = (select max(date(transminute)) from t_k_line_minute where stockid = '000300.SH')
    ;
    
  • 删除二进制日志

    PURGE BINARY LOGS TO 'mysql-bin.03';
    PURGE BINARY LOGS BEFORE 201506150000;
    
  • 查看warnings

    show warnings;
    
  • 删除原有主键,增加ID主键

    alter table TABLENAME drop primary key;
    alter table TABLENAME add column id bigint unsigned primary key auto_increment;
    
  • 授权

    grant all privileges on nxb.* to 'dbgateway'@'%' identified by 'xianji';
    
  • insert by select

    insert into banner_2_0_0 select * from t_banner_100;
    
  • 修改数据库属性

    ALTER DATABASE db_aofei_test CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    
  • 设置auto_increment起始值

    ALTER TABLE tbl AUTO_INCREMENT = 100;
    
阅读此文

2015-06-25
数据库中间件

阅读此文

2015-06-25
数据库-主键

好处

  • 维持实体完整性

  • 大大加快查询速度

  • 查询结果,默认按着主键排序

阅读此文

2015-06-25
mysql-字符串转数字

  • SELECT CAST(‘123’ AS SIGNED);

  • SELECT CONVERT(‘123’,SIGNED);

  • SELECT ‘123’+0;

阅读此文

2015-06-24
VirtualBox共享文件夹配置

环境

  • ArchLinux

步骤

  1. 安装模块

    pacman -S virtualbox-guest-modules
    
  2. 手动载入模块

    modprobe -a vboxsf
    

    若提示Module not found,则执行:

    depmod $(uname -r)
    
  3. 开机自动载入模块

    echo vboxsf >/etc/modules-load.d/virtualbox.conf
    
  4. 创建挂载点

    mkdir /data
    
  5. 在虚拟机控制中,加入共享文件夹

    E_DRIVE
    
  6. 挂载

    • 手动挂载

      mount -t vboxsf E_DRIVE /data
      
    • 自动挂载

      /etc/fstab
      
      E_DRIVE /data vboxsf
      

常见问题

  • 挂载失败

    错误提示:

    [cpp] view plaincopy
    mount: wrong fs type, bad option, bad superblock on E_DRIVE,
           missing codepage or helper program, or other error
           (for several filesystems (e.g. nfs, cifs) you might
           need a /sbin/mount.<type> helper program)
           In some cases useful info is found in syslog - try
           dmesg | tail or so
    

    解决过程:

    1. dmesg | tail

      sf_read_super_aux err=-22

    2. 查看vboxsf链接

      vincent@vincent-VirtualBox:/mnt$ ls -al /sbin/mount.vboxsf
      lrwxrwxrwx 1 root root 40 Jun 19 09:38 /sbin/mount.vboxsf -> /usr/lib/VBoxGuestAdditions/mount.vboxsf
      
    3. 发现链接不对,重新链接

      ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf
      

参考

  1. https://wiki.archlinux.org/index.php/VirtualBox#Installation_steps_for_Arch_Linux_guests
阅读此文

2015-06-24
django-manage常用命令

  • 查看某个命令帮助

    ./manage.py help command
    
  • 生成migrate操作

    python manage.py makemigrations
    
  • 执行migrate操作

    ./manage.py migrate
    
  • 生成多个数据库(1次migrate执行一个数据库)

    ./manage.py migrate
    ./manage.py migrate --database=stock_app
    
  • 创建用户

    ./manage.py createsuperuser
    
  • 修改用户密码

    ./manager.py changepasswd USERNAME
    
阅读此文