Big Bug Ban

兴趣 践行 创新

心跳电量0.1版 欢迎使用

 

icon

前段时候等电话面试电话.
结果手机又不争气..不知道什么时候就死机了
现在做了这个东西,加上电量显示特性
开启后LED将不断闪烁
您可以知道手机当前的状态
LED颜色会根据电量变化
点击开启服务即可
如果不想用了再点击关闭服务
截图就不上了..很丑的.

下载地址  [download id=”25″]

源代码  [download id=”26″]

ps:已经放到应用汇上面了..不过怎么我自己都没看到在哪里呢..囧

Written by princehaku

8月 8th, 2011 at 10:35 下午

Posted in Android

Tagged with

with 2 comments

好用的wordpress语法高亮插件! 自制

 

这是个wordpress语法高亮插件

和你现在用的大多数应该都不一样

根据范学长的建议.实现了在框框里面就能看到你高亮的代码

使用的时候点击编辑器上面的按钮

插入的代码会预先在编辑器里面看到

效果如下

然后你可以直接进行修改~

高亮部分使用google-code-prettify

示例如下

  1. <?php
  2. /**
  3.  * Media Library administration panel.
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Administration
  7.  */
  8.  
  9. /** WordPress Administration Bootstrap */
  10. require_once‘./admin.php’ );
  11.  
  12. if ( !current_user_can(‘upload_files’) )
  13. wp_die__‘You do not have permission to upload files.’ ) );
  14.  
  15. $wp_list_table _get_list_table(‘WP_Media_List_Table’);
  16. $pagenum $wp_list_table->get_pagenum();
  17.  
  18. // Handle bulk actions
  19. $doaction $wp_list_table->current_action();
  20.  
  21. ?>

================================================================

已经放到wordpress官网了  安装插件的时候搜索google-syntax就可以安装了

官网插件地址    http://wordpress.org/extend/plugins/google-syntax/

本地下载地址    [download id=”24″]

 

Written by princehaku

7月 29th, 2011 at 6:13 下午

Posted in php

Tagged with

with 9 comments

wordpress执行效率分析(一)

 

家宇学长说过,wordpress效率很低。

今日调测了一下,效率确实有点低

我的首页执行时间都到了1.5+秒。

来测试下,找出根源。

首先加上时间测试和内存测试代码

在index.php最前面放上

$GLOBALS[‘_beginTime’] = microtime(TRUE);

在最后面加上

$GLOBALS[‘_endTime’]=microtime(TRUE); echo “\r\nMem:”.number_format(memory_get_usage()/1024,2).”KB”; echo “\r\nExecTime:”.($GLOBALS[‘_endTime’]-$GLOBALS[‘_beginTime’]);

好了  然后看看效果

before

我的首页占用了17M内存  执行时间1.58s

囧..

这个是别忘的..

image

不管是执行时间还是所占用的内存都远远低于wp

是什么问题呢?

我记得每次有人访问wp的话wp都会去联网检查更新

那先把联网部分禁用掉试试

stophttp

更大了,平均值差不多也是这个。难道wp还写了死锁来检测网络连通?

还不太清楚,或许和服务器不稳定也有关系。

总之停止http外联不能加速

那试试吧插件关了. wp的插件机制是各种各样的action和filter

然后吧对应的函数暂存,需要用的时候再调出。

这个是吧插件关完的效果

stopplugin

稍微快了点

我们看看插件主要的代码

function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {global $wp_filter, $merged_filters; $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); $wp_filter[$tag][$priority][$idx] = array(‘function’ => $function_to_add, ‘accepted_args’ => $accepted_args); unset( $merged_filters[ $tag ] ); return true; }

函数都放在了$wp_filter这个变量里面

然后有个$idx  查了下..那个idx和索引无关..只是唯一标识符..

也就是说..他是用了一个线性表存的. 插件多了的话..效率自然就低下了..

然后再进一步测试  发现在载入theme前只耗费了0.3s

把$GLOBALS[‘_endTime’]=microtime(TRUE);

改到theme的head前加入

head

然后再foot里面再加入  时间又还是那么多了

也就是说中间部分占用了大量的资源

看看里面基本也就 只有个post

再检查看query的情况

首页最上面加入define(‘SAVEQUERIES’, true);

下面这样写
$total=0.0;

foreach($wpdb->queries as $i=>$j){

$total+=$j[1];

}

echo “\r\nMem:”.number_format(memory_get_usage()/1024,2).”KB”;

echo “\r\nQueryNums: “.count($wpdb->queries).” QueryTime:”.number_format($total,6).”s”;

echo “\r\nExecTime:”.number_format($GLOBALS[‘_endTime’]-$GLOBALS[‘_beginTime’],6).”s”;

整个首页代码应该是这样

queries as $i=>$j){
	$total+=$j[1];
}

echo "\r\nMem:".number_format(memory_get_usage()/1024,2)."KB";
echo "\r\nQueryNums: ".count($wpdb->queries)." QueryTime:".number_format($total,6)."s";
echo "\r\nExecTime:".number_format($GLOBALS['_endTime']-$GLOBALS['_beginTime'],6)."s";

?>

 

然后看看。。

首页有75条sql语句  但是执行时间只有0.194498s还有的时间去哪里了???

继续测试。。

Written by princehaku

7月 27th, 2011 at 11:27 上午

Posted in php

Tagged with

with 2 comments

诡异的shell问题

 

这是一段小代码

#!/bin/sh

read c

echo $c

读取一个字符然后显示出来

但是!!!!

不能运行!!

为什么??

我也不知道..

下载这个[download id=”23″]试试.

改个名就可以正常用了.

我表示很费解.

Written by princehaku

7月 8th, 2011 at 1:30 上午

Posted in linux

Tagged with

with 5 comments

中文数字转换成阿拉伯数字

 

最近做的东西有这个需求.

需要把中文的数字转换成阿拉伯的数字

比如 三千七百二十八万九百一十四

结果为 37280914

网上找了一些 但是效果不好.

自己写个

考虑下分析树.

image

这是一个递归的树.所以需要构造一个递归的分析器来进行词法分析

语义分析

语义:

“/一/” “/二/” “/三/” “/四/” “/五/” “/六/” “/七/” “/八/” “/九/” “/零/”

对应:

1 2 3 4 5 6 7 8 9 0

 

样例如下:

<?php

include "ChineseNumberConv.class.php";

$s=new ChineseNumberConv();

$sss=$s->toAlpha("三千七百二十八万零九百一十四");

echo $sss."<br />";

?>

注意: 文件编码需要互相对应,否则正则不能找到匹配的

fromAlpha 这个函数完成度不高.. 只能用于2位以下的 暂时不更新

toAlpha()的返回值就是转换后的数字

 

源代码下载 [download id=”22″ ]

 

Written by princehaku

7月 4th, 2011 at 2:23 下午

Posted in php

Tagged with

with 8 comments

flowphp即将发布~

 

今天弄了一下午
终于吧最后一个大模块/orm支持完成了
马上就可以和大家见面了
虽然写得很喽
有什么意见和建议请都告诉我~
我会不断改进的~

Written by princehaku

6月 27th, 2011 at 11:59 下午

Posted in php

with 3 comments

Android开发日志 闹钟

 

近期要做个东西,需要设计到闹钟的设置.

现在把遇到的问题和详细步骤的给大家分享下~

首先 闹钟是位于ALARM_SERVICE用AlarmManager进行管理

AlarmManager am = (AlarmManager)getSystemService();

用这一句就可以直接得到闹钟管理

然后你就可以设置闹钟了.

am.setRepeating(type, triggerAtTime, interval, operation)

或者

am.set(type, triggerAtTime, operation)           

type的话用AlarmManager.RTC_WAKEUP或者其他,参考SDK文档~

operation是一个PendingIntent

之所以要这个..是因为我们需要在程序退出后.时间到了也可以正常被系统调入然后执行

创建一个类继承BroadcastReceiver

/**
 * Copyright 2010 princehaku
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * User: princehaku
 * Date: 11-6-12
 * Time: 上午11:18
 */
package net.techest.alarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class AlarmReceiver extends BroadcastReceiver {

	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		Log.i("AR", "Time Up");

	}
}

然后onReceive上面就是闹钟响的时候执行的代码

还有就是这个类必须在mainfest.xml里面注册成监听

<receiver android:name=".AlarmReceiver" android:process=":remote" />

然后就可以使用了~

Written by princehaku

6月 12th, 2011 at 10:04 下午

Posted in Android

Tagged with

without comments

小工具-htaccess转换成其他类型

 

.htaccess是apache的默认的重写规则和站点配置文件

这个小工具可以吧它转换成lighttpd的重写规则

运行时把.htaccess文件放入即可

不保证100%有效..

 

安装文件:
[download id=”20″]

源代码:
[download id=”21″]

Written by princehaku

6月 5th, 2011 at 11:00 下午

Posted in c/c++

Tagged with

with 2 comments

linux限制进程–ulimit

 

ulimit 参数说明

选项 [options] 含义 例子
-a 显示当前所有的 limit 信息。 ulimit – a;显示当前所有的 limit 信息。
-H 设置硬资源限制,一旦设置不能增加。 ulimit – Hs 64;限制硬资源,线程栈大小为 64K。
-S 设置软资源限制,设置后可以增加,但是不能超过硬资源设置。 ulimit – Sn 32;限制软资源,32 个文件描述符。
-c 最大的 core 文件的大小, 以 blocks 为单位。 ulimit – c unlimited; 对生成的 core 文件的大小不进行限制。
-l 最大可加锁内存大小,以 Kbytes 为单位。 ulimit – l 32;限制最大可加锁内存大小为 32 Kbytes。
-u 用户最大可用的进程数。 ulimit – u 64;限制用户最多可以使用 64 个进程。
-v 进程最大可用的虚拟内存,以 Kbytes 为单位。 ulimit – v 200000;限制最大可用的虚拟内存为 200000 Kbytes。
-m 最大内存大小,以 Kbytes 为单位。 ulimit – m unlimited;对最大内存不进行限制。
-d 进程最大的数据段的大小,以 Kbytes 为单位。 ulimit -d unlimited;对进程的数据段大小不进行限制。
-s 线程栈大小,以 Kbytes 为单位。 ulimit – s 512;限制线程栈的大小为 512 Kbytes。
-t 最大的 CPU 占用时间,以秒为单位。 ulimit – t unlimited;对最大的 CPU 占用时间不进行限制。
-f 进程可以创建文件的最大值,以 blocks 为单位。 ulimit – f 2048;限制进程可以创建的最大文件大小为 2048 blocks。
-n 可以打开最大文件描述符的数量。 ulimit – n 128;限制最大可以使用 128 个文件描述符。
-p 管道缓冲区的大小,以 Kbytes 为单位。 ulimit – p 512;限制管道缓冲区的大小为 512 Kbytes。

Written by princehaku

6月 2nd, 2011 at 10:04 下午

Posted in linux

with 2 comments

真有喜感.

 

QQ3

– -..

不知道是谁..但是没改我的密码..

呵呵..密码回收!

Written by princehaku

5月 25th, 2011 at 10:49 下午

Posted in things goes by

with 10 comments