博文

修复yum更新途中退出导致的依赖问题

请使用 yum distro-sync full 参见:http://serverfault.com/questions/681486/

Pycharm的奇葩问题之神秘消失的列名提示

之前的Pycharm好好的,结果突然某天就无法正常的在SQL语句中提示Field Name了,取而代之的是给我一大堆的语法错误提示——提示说找不到对应的Field 结果今天仔细注意了一下右下角的Event Log中的Database提示: MySQL - @192.168.0.11          8508online.*          java.sql.SQLException: Table '8508online.fake_comment_type' doesn't exist          ..... 妈蛋,原来是数据库损坏导致Pycharm无法正常的结束Field的侦测流程导致整个SQL提示都不正常了…… 修复一下这几个顺坏的表之后,世界就一切正常了

Javascript对象创建的几种方式

本文是Nicholas的《Javascript高级程序设计》6.2章的读书笔记,仅在加强记忆 工厂模式。即用一个函数来生成类的实例 function creator(name, age, job){ var o = {}; o.name = name; o.age = age; o.job = job; o.getName = function(){ return this.name; }; return o; } var person1 = creator('siglud', 10, 'Engineer'); var person2 = creator('ethlin', 12, 'Doctor'); console.log(person1.getName == person2.getName); 这种方法的很好理解,就是构造一个能返回一个类实例的函数,但是弊端有两个,一是无法用反射知道一个对象的类型,因为这个对象的类型是Object(例子中我用{}来代替);二是getName作为一个函数本来是可以复用的,但是却其实生成了两个,所以在最后的console log中打印出了false 生成器模式。原版翻译为构造函数模式,但是这个“构造函数”明显是和C语言中的构造函数不是一个东西,所以我换个说法,其本质就是把函数本身作为一个类,用new关键字来生成一个新的函数(类)对象,因为JS中函数本身也是一个对象 function Person(name, age, job){ this.name = name; this.age = age; this.job = job; this.getName = function(){ return this.name; } } var person3 = new Person('siglud', 10, 'Engineer'); var person4 = new Person('ethlin', 12, 'Doctor'); console.log(pers...

在CentOS 7上用Apache+PHP建立虚拟主机

默认的CentOS就自带了Apache,本篇主要是用系统自带的Apache来完成的 首先先新建一个配置文件 vim /etc/httpd/conf.d/site.conf 内容如下: <VirtualHost *:80> DocumentRoot /home/www ServerName siglud.com.cn     <Directory />         Require all granted         AllowOverride All         DirectoryIndex index.php index.htm     </Directory> </VirtualHost> 然后systemctl restart httpd 打开iptables的端口 iptables -I INPUT -p tcp --dport 80 -j ACCEPT /usr/libexec/iptables/iptables.init save 这个时候去访问大部分都会收到403了,原因在于selinux chcon -Rv --type=httpd_sys_content_t /home/www 如果这个时候报错 那么执行 chcon -R -h system_u:object_r:usr_t /home/www/ 之后再执行它就可以了

适用于安装了Tomato的AC66U的Shadowsocks-libev客户端

一直在找Tomato对应的optware版本的ss,但是网上到处都是针对OpenWRT的预编译版本(比如 这里 ),找遍大街都没找到对应Tomato的,不过好心人还是有的 下载地址是: http://dl.lazyzhu.com/file/Toolchain/ss-libev/1.4.8-5d7dd372fc/mips/shadowsocks-libev-openssl_1.4.8_mipsel_uclibc.zip 通过这次也终于让我知道了,原来AC66U虽然在Tomato的首页显示的是Broadcom BCM5300 chip rev 1,但是其实却是Mipsel的芯片 这个东西解压之后是四个可执行文件,没有对应的安装包 如果自己懒得写启动脚本的话,可以善用 以前的安装包 下载安装之前的包之后,把解压之后的ss-redir拷贝到/opt/bin目录替换源文件就可以了 这下终于可以如愿以偿的使用rc4-md5加密方式了 参考链接: http://www.right.com.cn/forum/thread-138582-1-1.html http://mujj.us/post/510.html

用iptables限制NAT下每IP的网速

iptables -I FORWARD -d 192.168.0.119 -j DROP iptables -I FORWARD -m limit -d 192.168.0.119 --limit 300/sec -j ACCEPT 意思是限制对应ip的数据包下载流量为每秒300个包,这个数量x mtu的值1500(1.5K),实际速度大概是450K/s iptables -I FORWARD -s 192.168.0.119 -j DROP iptables -I FORWARD -m limit -s 192.168.0.119 --limit 300/sec -j ACCEPT 同样的,这样可以限制上传速度 iptables -I FORWARD -p tcp -s 192.168.0.0/24 -m connlimit --connlimit-above 20 -j REJECT iptables -I INPUT -p tcp -s 192.168.0.0/24 -m connlimit --connlimit-above 20 -j REJECT 这样可以限制连接数

在CentOS 7上用Systemd建立shadowsocks自动启动服务

CentOS 7开始使用Systemd替代原有的init.d作为启动管理工具,原本以为很复杂,后来发现其实比init.d还要简单。 安装完shadowsocks-libenv之后: vim /etc/systemd/system/ss-redir.service 写入以下内容: [Unit] Description=Shadowsocks Redir Client After=network.target [Service] Type=forking PIDFile=/run/shadowsocks/redir.pid PermissionsStartOnly=true ExecStartPre=/bin/mkdir -p /run/shadowsocks ExecStartPre=/bin/chown nobody:nobody /run/shadowsocks ExecStart=/usr/local/bin/ss-redir -f /var/run/shadowsocks/redir.pid -c /usr/local/etc/ss-redir.json Restart=on-abort User=nobody Group=nobody UMask=0027 [Install] WantedBy=multi-user.target 然后运行 systemctl enable ss-redir.service 启用此服务的自动运行 开启服务:systemctl start ss-redir 查看状态 systemctl status ss-redir