都是些很零碎的 tips,涉及到 linux, wordpress, css, php, English … 选择性阅读吧!

Douban and PHP

按照之前 QQ 签名秀 的原理把豆瓣的个人广播系统也给提取出来了,效果请见此 test 页面

使用方法是把以下代码添加到你的页面里:

<script type="text/javascript" src="http://punkid.org/glade/douban/request.php?userid=username&numbers=5"></script>

其中 userid 后面跟的是你的豆瓣用户名,numbers 后面是显示条目数 ( 最多 10 条 )。至于怎么 polish 这个 douban 的 miniblog 纯粹是你的 CSS 活。对了,输出编码是 UTF-8。

PHP tips: 用 addslashes 这个函数可以对字符串进行转义。

Linux

1. Tired of emerging the world?

emerge $(eix -Iuc --format-compact "<category>/<name>" dev-libs/* | head -n -1)

可以用来更新某一 category( 例如 dev-libs) 下的已安装软件。

2. Ape 转 mp3

emerge shntools 和 mac-port (gentoo-china overlay 提供 ) 后运行:

shnsplit -f filename.cue -t "%n - %t" -o "cust ext=mp3 lame --preset extreme - %f" filename.ape

会根据 cue 文件对 ape 进行切割成按 tracknumber - trackname 命名的 mp3 文件,不过 ID3 信息没法保存进去,交给 Musicbrainz 搞定吧。

3. 使用 Aria2 下载器

原来用的 axel 不知何故在我的电脑上经常出现 Initialing download 就停滞不前的情况,无奈…换了个稍微大点的 Aria2。顺便把 Gentoo Mirror 的默认下载也换成了 aria2。更改 make.conf 如下:

FETCHCOMMAND="/usr/bin/aria2c -c -s 4 -d ${DISTDIR} -o ${FILE} ${URI}"
RESUMECOMMAND="${FETCHCOMMAND}"

至于在 firefox 里用 flashgot 启用 aria2 下载,在 Executable path 里填 /usr/bin/rxvt ( 任意虚拟终端,别用 xterm 就是了,那个启动太慢了 ),然后在 Command line arguments template 里填 -e aria2c -s 5 -d [FOLDER] [URL]

Wordpress

1. 只显示当日评论数

不明白我的意思的,留个言在到首页看下就知道了,当日有留言的日志会格外用类似于 3 comments today 方式显示。方法很简单,抽数据而已。修改你的模板的 index.php,再最顶端添加:

<?php 
	$nowtime = current_time('timestamp');
	$today = date('Y-m-d G:i:s', mktime(0, 0, 0, date('m',$nowtime), date('d',$nowtime), date('Y',$nowtime))); 
?>

然后是修改 loop 部分:

<?php if (have_posts()) : ?>
	<?php while (have_posts()) : the_post(); ?>								
		<?php $today_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_date >= '$today' AND comment_approved = '1'"); ?>	
		<div class="entry"
			<h2 id="post-<?php the_ID(); ?>" class="entrytitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
			<p class="metadata clearfix">
			<span class="cmt"><?php if ($today_comments > 0) { ?><a class="todaycmt" href="<?php the_permalink() ?>#comments" title="Comment on <?php the_title(); ?>"><?php echo $today_comments; ?> Comment<?php if ($today_comments>1) echo 's'; ?> Today</a><?php } else { ?><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><?php } ?></span>
			</p>
			...
		</div>
	<?php } ?>
	...
<?php endif; ?>

加重部分是关键。

2. 过滤某 category 的 feed 输出

在模板的 function.php 里添加这段代码:

<?php
function RssFilter($query) {
	if ($query->is_feed) {
    	$query->set('cat','-22');
    }
    return $query;
}

add_filter('pre_get_posts','RssFilter');
?>

其中 22 为你的 category ID。

CSS

CSS 的代码书写风格我倾向于单行式,用缩进表明元素的从属关系。例如:

#secondary div.modules {margin-bottom:40px;}
	#secondary div.modules a {color:#888;}
	#secondary div.modules a:hover {color:#FF32B3;text-decoration:underline;}
	#secondary div.modules h3 {color:#94C742;border-bottom:1px dotted #94C742;}
	#secondary div.modules ul li {padding:3px 8px;border-bottom:1px dashed #FF80D0;}
	#secondary div.modules ul li:hover {background:#F0F8E2;}

#bottom_wrapper h3 {color:#FDF262;border-bottom:1px solid #FDF262;}
	#bottom_wrapper div.modules {width:300px;margin:0 10px;float:left;position:relative;display:inline;}
	#bottom_wrapper div.modules ul li {height:1.6em;padding:3px 2px;border-bottom:1px dotted #528F08;overflow:hidden;}
	#bottom_wrapper div.modules ul li:hover {background:#528F08;}
	#bottom_wrapper div#misc table.calendar {width:300px;margin-bottom:20px;border-collapse:separate;border-spacing:1px;}
		table.calendar td {padding:3px 0 2px;text-align:center;}
		table.calendar td.calendar_h {display:none;}
		table.calendar td.today {background:#528F08;}
		table.calendar td.week {background:#528F08;color:#FDF262;}
	#bottom_wrapper div#tags ul li {margin-right:5px;padding:0;display:inline;border:0;}	
		#bottom_wrapper div#tags ul li span, #bottom_wrapper div#tags div {display:none;}

也许这种单行的方式不利于阅读,但是类似 block 的书写方式最大的问题是一旦 CSS 代码上个几百行的,要找到某一行翻页是件很痛苦的事,而单行定义加上适当的缩进即便不看 HTML 源代码也能对页面结构有个基本的认识。还有就是…在 VIM 下用 w,b 进行整词跳跃是件很惬意的事,即便是单行也能很快的跳跃到需要修改查看的 property。

English

1. take with a pinch of salt

Radiohead 的 A Wolf at the Door 里有句歌词是 Take it with the love its given, take it with a pinch of salt, take it to the taxman

take it with a pinch of salt 真的是抓把盐吗? 真实的意思有点类似于姑且相信,半信半疑的意思,例如 Regarding what you said yesterday, I would take it with a pinch of salt 意思就是你昨天说的那些我姑且相信吧。

Tia Dalma and I go way back

在电影 Pirates of the Carribean : The Man’s Chest ( 加勒比海盗 2:聚魂棺 ),Jack 船长带着众人去找女巫 Tia Dalma 时说: No worries, mates. Tia Dalma and I go way back.。我记得当时我看的思路的版本翻译成了 伙计们,别担心,Tia Dalma 和我待会就回来。这其实是错误的,go back way 的意思是表示两人认识很久了,交情很好。