存档在 ‘code’ 分类

AIR Helloworld

2010年3月2日

使用AIR快速开始一个Helloworld程序

关键步骤:
1、安装AIR环境
2、安装SDK
3、构建Helloworld项目
4、安装并测试Helloworld项目
==========================================
具体细节:
1、安装AIR环境
* 到Adobe下载AIR环境
* 安装AIR环境 ,本文使用的是 Adobe AIR 1.5.3.9130 版本
————————————————–
2、安装SDK
* 到Adobe下载SDK
* 将下载到的SDK包解压并放置到运行目录
本文下载的SDK版本为 adt version “1.5.3.9120″
本文SDK安装目录为 D:\Program Files\Adobe\AdobeAIRSDK
* 配置环境变量 将AIR SDK的工作路径添加到 PATH 变量中,(使adt和adl可以在任意目录以短路径方式启动)
PATH = [... 保持原有的PATH值不变];D:\Program Files\Adobe\AdobeAIRSDK\bin
————————————————–
3、构建Helloworld项目
* 创佳Helloworld项目
1)、创建Helloworld目录
本文全路径为 e:\learn\AIR\Helloworld
进入 Helloworld ,开始构建 helloworld 应用
除非明确说明 否则之后描述的文件和路径都是相对于此路径开始
2)、创建项目描述文件 HelloWorld-app.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.5">
    <id>examples.html.HelloWorld</id>
    <version>0.1</version>
    <filename>HelloWorld</filename>
    <initialWindow>
        <content>HelloWorld.html</content>
        <visible>true</visible>
        <width>400</width>
        <height>200</height>
    </initialWindow>
</application>

3)、创建应用界面 HelloWorld.html

<html>
<head>
    <title>Hello World</title>
    <script type="text/javascript" src="AIRAliases.js"></script>
    <script type="text/javascript">
        function appLoad(){
            air.trace("Hello World");
        }
    </script> 

</head>
<body onLoad="appLoad()">
    <h1>Hello World</h1>
</body>
</html>

4)、测试应用
* 打开 cmd 并 cd 进入应用目录
* 运行命令 adl HelloWorld-app.xml
* > 系统将调用AIR运行时,启动一个400×200的窗口应用并呈现Helloworld字符
* > 系统在控制台输出 Hello World 字符
————————————————–
4、安装并测试Helloworld项目
1)、生成自签名证书和密钥对
* 运行命令 adt –certificate -cn SelfSigned 1024-RSA sampleCert.pfx samplePassword
* 系统将在当前目录生成密钥文件 sampleCert.pfx
2)、创建 AIR 安装文件
* 运行命令 adt -package -storetype pkcs12 -keystore sampleCert.pfx HelloWorld.air
HelloWorld-app.xml HelloWorld.html AIRAliases.js
* 根据系统提示输入密钥文件的密码 samplePassword
* 系统将根据 helloworld-app.xml 的描述生成AIR应用程序,并将helloworld.html 和 airaliases.js 当作附加资源嵌入AIR应用程序中
3)、安装 Helloworld 应用
* 双击 helloworld.air 或在命令行下执行 hellowrold.air 命令
* 系统调用本地的air运行时环境解释helloworld.air并开始应用安装
* 根据系统提示进行安装
4)、当安装完成后,通过双击helloworld的快捷方式或到安装目录打开helloworld.exe 即可运行helloworld应用
————————————————–
参考:
* 使用 AIR SDK 创建第一个基于 HTML 的 AIR 应用程序http://help.adobe.com/zh_CN/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7ecc.html
——————————————
资源:
* 使用 HTML 和 Ajax 开发 Adobe AIR 1.5 应用程序
* 针对 HTML 开发人员的 AIR 语言参考
* Flex 3.2 语言参考
* Adobe AIR 开发人员中心

使用mysqldump进行单表备份

2008年10月10日

写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选

bak_db_table.sh
————————————————————–

# bak_db_table.sh db db_host db_user db_passwd > log.txt
# by fallseir at 20081010

if [ $1 ] # 如果没有参数
then
echo database $1;
else
echo 'backup database tables to gzip files
sh bak_db_table.sh db [db_host] [db_user] [db_passwd]
'; exit;
fi

# 参数赋值
[ $1 ] && db=$1
[ $2 ] && dbh=$2
[ $3 ] && dbu=$3
[ $4 ] && dbp=$4

# 配置数据库参数
[ $dbh ] && dbh="-h"$dbh
[ $dbu ] && dbu="-u"$dbu
[ $dbp ] && dbp="-p"$dbp

#如果不存在 以db命名的目录 则创建
[ -a $db ] || mkdir $db; echo "mkdir $db"

# 获取数据库中的表列表
echo 'list=(`echo "show tables;"|mysql -h$dbh -u$dbu -p$dbp $db`)'
list=(`echo "show tables;"|mysql $dbh $dbu $dbp $db`)
# 获取表个数
tbcount=$((${#list[@]}-2))
if [ $tbcount= -2 ] # 如果表不存在 或数据库连接失败
then
  echo empty tables in $db or connent failed! ; exit 1;
fi
echo table count: $tbcount

# 对每个表进行备份 并压缩
# 使用gzip -d $file 进行解压
# 使用 mysql $database < $bakfile 进行恢复
for (( i = 1 ; i < ($tbcount+1) ; i ++ ))
do
  table=${list[$i]}
  echo back table $table
  mysqldump $dbh $dbu $dbp $db $table | gzip -c > $db/177.6.db.$db.$table.gz
# $? 前一命令的返回值, 0 为成功 1为失败 但mysqldump没有遵守这个约定
  echo back table $table $?
  sleep 10
done

一段用于替换字符串中指定的key的代码

2008年5月6日

一段用于替换字符串中指定的key的代码

–[[User:Fallseir|飞扬轻狂]] 2008年5月6日 (二) 02:32 (PDT)
$str=mapKeys($formatstr,$maps);

$str=“replace this template string !the key maps is here
key1=>{key1},key{{2=>{key{2},key3}=>{key3{}}”
;
echo 
mapKeys($str
  
,array(“key1″=>“value 1″
  
,“key{2″=>“value 2″
  
,“key3}”=>“value 3″
  
)
);
echo 
“\n”

output>>
replace this template string !the key maps is here
key1=>value 1,key{2=>value 2,key3}=>value 3
abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%,
abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,

$ php -r ‘highlight_file(“test.php”);’


<?php
/** test */
$str="replace this template string !the key maps is here
key1=>{key1},key{{2=>{key{2},key3}=>{key3{}}"
;
echo 
mapKeys($str
  
,array("key1"=>"value 1"
  
,"key{2"=>"value 2"
  
,"key3}"=>"value 3"
  
)
);
echo 
"\n";

$str="abc{key}{}}%{%{}%%%}%{{%{0{}%%,%%%,{key},%%,%%{key,2},%%{key,2},%$$%%{,%,";
echo 
mapKeys($str,array("key"=>"[the abc value]"
,"key,2"=>"[the %value% 2]"));
echo 
"\n";

$str="abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,";
echo 
mapKeys($str,array("key"=>"[the abc value]"
    
,"key,2"=>"[the %value% 2]"),"|%|");
echo 
"\n";
//end test*/
/*
$ php test.php
output>>
replace this template string !the key maps is here
key1=>value 1,key{2=>value 2,key3}=>value 3
abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%,
abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,
 
 */
 
 
/**
 * 使用maps中定义的value替换对应其key的由开始标记字符和结束标记字符包含的字符串
 *
 * 当标记对外开始标记后跟着开始标记时或结束标记时表示第一个开始标记为转义符
 * 当标记对内开始标记后跟着结束标记时表示第一个开始标记为转义符
 * 末尾没有匹配的开始标记将原样输出
 */
function mapKeys($str,$maps,$fstart=null,$fend=null){
  if(!
$fstart){
      
$fstart="{";
      
$fend="}";
  }
  if(!
$fend){
    
$fend=$fstart;    
  }
  
  
// 如果标记相同则使用mapKeysBase进行替换
  
if($fstart==$fend){return mapKeysBase($str,$maps,$fstart);}
 
  
$index=0;
  
$offset=0;
  while(
false!==($index=strpos($str,$fstart,$offset))){
    
# 找到开始标记,处理开始标记之前的数据
    
$v=substr($str,$offset,$index-$offset);
    
$offset=$index+strlen($fstart);
    
$p=true;
    while((
$find=substr($str,$offset,strlen($fstart)))==$fstart
      
||($find=substr($str,$offset,strlen($fend)))==$fend){
      
$v.=$find;
      
$offset=$offset+strlen($find);
      
$p=false;# 如果这个标记是用来转义的
      
if(false!==($index=strpos($str,$fstart,$offset))){
        
$v.=substr($str,$offset,$index-$offset);
        
$offset=$index+strlen($fstart);
        
$p=true;# 查找下一个开始标记
      
}
    }
    
$o.=$v;
    
$v="";
    
# 标记了开始 并找到了 结束
    
while($p
      
&&false!==($end=strpos($str,$fend,$offset))){
      
$v.=substr($str,$offset,$end-$offset);
      
# 如果这个标记是被转义的
      
if(($find=substr($str,$end-strlen($fend),strlen($fstart)))
        ==
$fstart){
        
$v=substr($v,0,strlen($v)-strlen($fstart)).$fend;
        
$offset=$end+strlen($fend);
        continue;
      }
      
$p=false;
    }
    if(
$v){
      if(
array_key_exists($v,$maps)){
        
$v=$maps[$v];
      }else{
        
$v="[".$v."]";
      }
      
$o.=$v;
      
$offset=$end+strlen($fend);
    }
  }
  if(
$p){
    
$o.=$fstart;
  }
  
$v=substr($str,$offset);
  
$o.=$v;
  return 
$o;
}
/**
 * 使用maps中定义的value替换对应其key的由标记字符包含的字符串
 *
 * 如果标记重复出现 则第一个为转义字符(这也意味着标记字符不能作为key的开始字符)
 */
function mapKeysBase($str,$maps,$find=null){
  if(!
$find){
    
$find="%";
  }
  
$p=false;
  
$v="";
  
$index=0;
  
$offset=0;
  while(
false!==($index=strpos($str,$find,$offset))){
    
$v.=substr($str,$offset,$index-$offset);
    
$offset=$index+strlen($find);
    while(
substr($str,$offset,strlen($find))==$find){
      
$v.=$find;
      
$offset=$offset+strlen($find);
      if(
false!==($index=strpos($str,$find,$offset))){
        
$v.=substr($str,$offset,$index-$offset);
        
$offset=$index+strlen($find);
      }
    }
    if(
$p){
      if(
array_key_exists($v,$maps)){
        
$v=$maps[$v];
      }else{
        
$v="[".$v."]";
      }
      
$o.=$v;
      
$v="";
      
$p=false;
    }else{
      
$o.=$v;
      
$v="";
      
$p=true;
    }
  }
  if(
$p){
    
$v.=$find;
  }
  
$v.=substr($str,$offset);
  
$o.=$v;
  return 
$o;
}
?>


取自”http://www.fallseir.com/wiki/PHP/MapKeys.html

Win下出现apache无法启动的解决方式

2008年5月6日

Win下出现apache无法启动的解决方式

使用xampp时,时常会遇到apache启动不了的情况,而xampp的控制面板有没有什么像样的提示 只有一个”Busy…”

但重启Win后,先启动apache就不会遇到问题。

但是事情总是有原因的,决定去查下,也许是xampp给的提示不足,而不是apache的问题,

> cmd
> d:\
> cd tools\xampp\apache\bin\ #我的apache安装位置
> httpd # apache的启动程序

(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。  : make_sock: c
ould not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
# 找到原因了 原来是我的80端口被占用了

> netstat -ano # 查看网络状态

  Proto  Local Address          Foreign Address        State           PID
  TCP    127.0.0.1:80           127.0.0.1:1920         CLOSE_WAIT      1112
  TCP    127.0.0.1:80           127.0.0.1:2016         CLOSE_WAIT      1112
  ...
# 通过 Local Address 中端口为80的行 可以看到 我的80端口被PID为1112的进程占用了

任务管理器>进程 / 工具栏 > 查看 > 选择列 在“PID(进程ID)”项上打勾
在进程列表中 查找PID为1112的进程
# 我这里是该死的迅雷 !!
# 当然之前我还遇到过QQ的时候
ok 杀掉这个进程 或者关掉罪魁,启动Apache 道路终于通畅了!^_~

取自”wiki:Win下出现apache无法启动的解决方式

code: 页面跳转 – php 语句收集

2007年6月26日


<?php
function page_redirect($redirect_to){
    if (
headers_sent()){ // Use JavaScript to redirect if content has been previously sent (not recommended, but safe)
        
echo '<script language="JavaScript" type="text/javascript">window.location='';
        echo 
$redirect_to;
        echo 
'';</script>';
    }else{    
// Default Header Redirect
        
header('Location: ' $redirect_to);
    }
}
?>