Lastest

优雅地自定义遍历输出文章

背景介绍 看了不下十个主题的代码,一个通病,就是控制代码和模板混写在一起。如下图 这么写的问题是什么? 当输出结构比较复杂的时候,html会变得非常难以修改。 typecho自己是如何做的 作为一个typecho新手,很好奇为什么系统内置的文章输出就可以如此优雅。一个while($this->next())实现文章遍历,模板随意修改,数据控制代码也随意修改,互不干涉。 以下是所有模板中都用到的,输出文章列表的代码。 <?php while($this->next()): ?> <article class="post_summary"> <h3 class="title"><a target="_blank" itemtype="url" href="<?php $this->permalink() ?>"><?php $this->title() ?></a></h3> <div class="row"> <div class="col-lg-3"> <a href="<?php $this->permalink() ...

golang之内存管理make

介绍 读《network programming with golang》这本书,墙裂推荐。读这本书之前我并没有系统的学过这门语言。读到第十章,Dictionary内存分配的代码让我觉得有些困惑,为什么一个定义长度为100的数组不会越界 问题 书中代码如下 v := make([]*Entry, 0, 100) for n := 0; n < len(d.Entries); n++ { de := d.Entries[n] if de.Pinyin == py { v = append(v, de) } } 这段代码,看起来就是在最初创建了一个长度为100的数组,而后不断的通过append给它添加新的元素。添加多少个元素是不确定的,那么如果添加101个元素,会不会index of range呢? 实验 带着这个问题我做了如下实验。实验代码如下 package main import "fmt" func main(){ array := make([]int, 0, 10) // 越界错误: index out of range //array[0] = 1 // ok 可以访问 array = array[0:1] array[0] = 1 // 越界错误: in...

MySQL复合语句用法

update和select联用, 将advid=2记录的数据同步更新到advid=14 update advertisement A inner join advertisement B set A.title = B.title, A.targets = B.targets, A.parameters= B.parameters, A.code = B.code where A.advid=14 and B.advid=2 insert和select联用, 将advid=4记录的数据拷贝出来,定义type字段为xxx,作为新纪录插入 INSERT INTO advertisement (available, type,displayorder, title, targets,parameters, code,starttime,endtime) SELECT available, "xxxx" as "type",displayorder, title, targets,parameters, code,starttime,endtime FROM advertisement WHERE advid = 4 mysql拷贝root用户,改名,并修改允许登录为% INSERT INTO user ( Host, User, Select_priv...

Discuz 3.4顶部格子广告显示列数修改

背景 一直以来都特别鄙视Discuz,Wordpress这种结构混乱的项目。平心而论,十多年前的代码,功能强大,运行稳定自然是没得说的。但是代码质量就不敢恭维了。所以一直以来都不愿意去碰这类项目,然而,人生不如意十之八九,偏偏就有这类项目飞脸上来。有钱不赚非君子,干吧 问题描述 为discuz安装插件,添加了顶部格子广告位。广告位默认一行显示5张广告图,然而客户要求一行3张。 解决方法 位置:source/class/adv/adv_text.php 这段代码,把两个5都改成3即可 $advcount = count($adids); if($advcount > 5) { $minfillpercent = 0; for($cols = 5; $cols >= 3; $cols--) { if(($remainder = $advcount % $cols) == 0) { $advcols = $cols; break; } elseif($remainder / $cols > $minfillpercent) { $minfillpercent = $remainder / $cols; $advcols...

python循环中修改数组元素

简单说下,就是for each这种方式,无法对原数组元素进行修改。 下面这段代码无法对原数组元素产生影响 content = ["aaa", "bbb", "ccc"] for item in content: item += "111" # 不影响原数组 print(content) 结果: ['aaa', 'bbb', 'ccc'] 需要使用这种方式 content = ["aaa", "bbb", "ccc"] for pos in range(len(content)): content[pos] += "111" print(content) 结果: ['aaa111', 'bbb111', 'ccc111'] 注意,这个样子也无法达到修改目的。要想达到保存修改目的,必须使用content[pos] = "xxxx"进行保存 content = ["aaa", "bbb", "ccc"] for pos in range(len(content)): item = content[pos] item += "1111" print(content)

Discuz x3.4是如何求密码hash的

首先说密码是如何生成的,废话不多说,直接上实验代码 <?php function discuz_password_hash($password, $salt){ return md5(md5($password) . $salt); } $salt = "anysalt"; $password = "123456789"; $hash = discuz_password_hash($password, $salt); echo $hash; salt从哪里来? 数据表: UCCENTER member数据表,username password,salt都在那里

Python使用类似JQuery的css选择器语法来处理html文档

Scrapy作为一个爬虫开发框架提供了内置的Selector组件来处理html文档,然而他的语法实在是有点诡异,大约平日前端开发用惯了JQuery的缘故吧,总想找一款具有类似语法的python组件来帮助处理html文档。 技术选型 稍微google下(感谢搜索引擎赐予我的力量。。),就找到了两款类似功能的组件: PyQuery: https://pythonhosted.org/pyquery/index.html#full-documentation BeautifulSoup 4 https://www.crummy.com/software/BeautifulSoup/bs4/doc/# 选择哪个呢? 首先看一下文档功能吧 对于pyuery,截图中可以看出它实现了类似JQuery的css选择器语法,满足要求。同时文档目录还显示,它除了支持css选择器外,还可以操作dom,可以进行ajax操作。先不管细节,至少看上去是满足要求的。 ![pyquery.png][1] 对于BeautifulSoup,很明显他也满足我们的基本要求。支持css选择器。 ![BeautifulSoup4.png][2] 成熟度 PyQuery当前版本1.2.4,而BeautifulSoup已经是第四版本了。BeautifulSoup 4要成熟些。 文档 PyQuery也不知道是功...

CentOS无法安装Scrapy解决

CentOS 7上安装Scrapy报错,提示说Twist构建失败,另外找不到python.h头文件目录。 #pip install scrapy gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/twisted/test/raiser.c -o build/temp.linux-x86_64-2.7/src/twisted/test/raiser.o s...

CentOS 7升级python 3.6

下载python 3.7源代码 cd /home/source wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz 解压缩源代码并编译安装 tar xvf Python-3.6.6.tar.xz cd cd Python-3.6.6 # 非生产环境请使用 #./configure # 生产环境请开启优化 ./configure --enable-optimizations make && make install 更换默认python软连接到python 3.6 mv /usr/bin/python /usr/bin/python2.7.5 ln -s /usr/local/bin/python3.6 /usr/bin/python 调整yum配置文件中用到的python版本 vim /usr/bin/yum 第一行把 #!/usr/bin/python 替换为 #!/usr/bin/python2.7.5 vim /usr/libexec/urlgrabber-ext-down 第一行把 #!/usr/bin/python 替换为 #!/usr/bin/python2.7.5 vim /usr/bin/repoquery 第一行把 #!/usr/bin...

python 3使用supervisor做守护进程

问题 centos 7系统,python 3.6环境下用pip install supervisor会报错, 简单说就是supervisor不支持python 3 [root@li999-188 python-supervisor]# pip3 install supervisor Collecting supervisor Using cached https://files.pythonhosted.org/packages/44/60/698e54b4a4a9b956b2d709b4b7b676119c833d811d53ee2500f1b5e96dc3/supervisor-3.3.4.tar.gz Complete output from command python setup.py egg_info: Supervisor requires Python 2.4 or later but does not work on any version of Python 3. You are using version 3.6.6 (default, Aug 6 2018, 01:04:23) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]. Please install using a support...