nasdaqhe's blog

被生活强jian着
posts - 66, comments - 42, trackbacks - 0, articles - 12
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

2011年5月15日

 1.获取编译工具下面要用来编译源代码,如果已经安装可跳过这步
  [bash] sudo apt-get install build-essential [/bash]
 
 2.安装PEAR and memcached
  [bash] sudo apt-get install php-pear memcached [/bash]
 
 3.编译libmemcached
  到 https://launchpad.net/libmemcached/+download 下载最新的libmemcached源代码,解压编译安装步骤如下:
  Extract the files with your preferred method, or type:
  [bash] tar -xzf libmemcached-0.37.tar.gz [/bash]
  Move into the extracted directory:
  [bash] cd libmemcached-0.37/ [/bash]
  Configure the package.
  [bash] ./configure –with-memcached [/bash]
  Make.
  [bash] make [/bash]
  Make install. Note this probably will require sudo rights.
  [bash] sudo make install [/bash]
 
 4.PECL
  [bash] sudo pecl install memcached [/bash]
  When this process completed, you should see something like this:
  [bash]
  Build process completed successfully
  Installing ‘/usr/lib/php5/20060613+lfs/memcached.so’
  install ok: channel://pecl.php.net/memcached-1.0.0
  Extension memcached enabled in php.ini
  [/bash]

 

 5.修改PHP.INI添加扩展
  [bash] sudo vi /etc/php5/fpm/php.ini [/bash] 
  在php.ini 中添加“extension = memcached.so”
  重启PHP-FPM服务
  [bash] sudo service php5-fpm restart [/bash] 
 

 

posted @ 2011-05-15 23:44 nasdaqhe 阅读(129) 评论(0) 编辑

//telnet IP Port 连接到memcached服务器
输入 telnet 192.168.12.14 11211 
//查看服务器状态
输入 stats
返回一堆状态
//SetValue 格式 set keyName 0 过期时间 数据长度,注意数据长度必须是Value的字节长度,如果两者不一致会报错
输入 set key1 0 10 5
输入 abcde
返回 STORED 表示设置成功
//GetValue
输入 get key1

posted @ 2011-05-15 23:25 nasdaqhe 阅读(125) 评论(0) 编辑

2011年5月10日

关键步骤如下:

1.将 DateTime 转换成 long 型。
2.索引时要使用 NumericField 进行索引
3.搜索时使用 NumericRangeQuery 进行查询

 事例代码如下:

  [TestMethod()]

        public void RangTest()
        {
            RAMDirectory mDirInfo 
= new RAMDirectory();
            IndexWriter mIndexWriter 
= new IndexWriter(mDirInfo, CAnalyzerLoader.GetAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
            mIndexWriter.AddDocument(GetDocumentByModel(
1"姑姑,我是态儿", CDateTime.UNIX_TIMESTAMP(System.DateTime.Now.AddDays(-1))));
            mIndexWriter.AddDocument(GetDocumentByModel(
2"B儿,我是态儿", CDateTime.UNIX_TIMESTAMP(System.DateTime.Now.AddDays(-2))));
            mIndexWriter.AddDocument(GetDocumentByModel(
3"肝儿,我是态儿", CDateTime.UNIX_TIMESTAMP(System.DateTime.Now.AddDays(-3))));
            mIndexWriter.Close();
            
long upper = CDateTime.UNIX_TIMESTAMP(DateTime.Now.AddDays(-1));
            
long lower = CDateTime.UNIX_TIMESTAMP(DateTime.Now.AddDays(-3).AddHours(-1));
            NumericRangeQuery rangeQuery 
= NumericRangeQuery.NewLongRange("UpdateOn", lower, upper, truetrue);

            IndexSearcher mSearcher 
= new IndexSearcher(mDirInfo, true);
            TopDocs topDocs 
= mSearcher.Search(rangeQuery, 100);
            Assert.AreEqual(
2, topDocs.totalHits);
        }

        
private Document GetDocumentByModel(int tid,string title,long time)
        {
            Document doc 
= new Document();
            doc.AddFiled(
"Id", tid.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)
                .AddFiled(
"Title", title.Trim(), Field.Store.YES, Field.Index.ANALYZED)
                .AddLongFiled(
"UpdateOn", time, Field.Store.NO, true);
            
return doc;
        }
        
public static Document AddFiled(this Document self, string name, string value, Field.Store fStore, Field.Index fIndex)
        {
            Field filed 
= new Field(name, value, fStore, fIndex);
            self.Add(filed);
            
return self;
        }
        
public static Document AddLongFiled(this Document self, string name, long value, Field.Store fStore, bool bIndex)
        {
            NumericField filed 
= new NumericField(name, NumericUtils.PRECISION_STEP_DEFAULT, fStore, bIndex).SetLongValue(value);
            self.Add(filed);
            
return self;
        }

posted @ 2011-05-10 17:38 nasdaqhe 阅读(79) 评论(0) 编辑

2011年4月7日

select [id],[poster],[fid],[title],[editername],[modifytime] from(
select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over
( order by id desc) as row from [news] WITH (NOLOCK) 
 where   path like 'A_B%' and  id not in 
 (select id from [news] where layer=7 or layer=5)) a  
 where row between 1 and 15
 

 上面的查询很慢。如果只执行子查询就很快,但是做 where row between 1 and 15 分页就很慢很慢,原来是因为查询里面用了or,优化成下面的就不超时了

 
 select [id],[poster],[fid],[title],[editername],[modifytime] from(
select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over
( order by id desc) as row from [news] WITH (NOLOCK) 
 where   path like 'A_B%' and  id not in 
 (select id from [news] where layer=7 union select id from [news] where layer=5)) a  
 where row between 1 and 15

posted @ 2011-04-07 09:29 nasdaqhe 阅读(37) 评论(0) 编辑

2010年12月23日

通过rel="search",把你的搜索功能放到浏览器的快捷搜索工具上

用firefox打开taobao时,看一下地址栏边上的快捷搜索时,可以填加一个“淘宝搜索”,完成后,以后就可以直接在那里搜索东西了!



rel search

实现方法:
在首页的head标签里加上 “<link rel="search" type="application/opensearchdescription+xml" href=provider.xml" title="关键词搜索" />”


provider.xml的写法为:
<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 <InputEncoding>UTF-8</InputEncoding>
 <ShortName>关键词搜索</ShortName>
 <Description>关键词搜索</Description>
 <Image height="16" width="16" type="image/vnd.microsoft.icon">images/favicon.ico</Image>
 <Url type="text/html" template="search.php?keyword={searchTerms}" />
</OpenSearchDescription>

------------------------------------------------------------------------------------------------------------------------------------------------- 

 

通过name="viewport" 在iPhone的浏览器中页面将以原始大小显示

 

网页手机wap2.0网页的head里加入下面这条元标签,在iPhone的浏览器中页面将以原始大小显示,并不允许缩放。

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> 

其中:
width - viewport的宽度 height - viewport的高度 
initial-scale - 初始的缩放比例
minimum-scale - 允许用户缩放到的最小比例 
maximum-scale - 允许用户缩放到的最大比例
user-scalable - 用户是否可以手动缩放

posted @ 2010-12-23 21:39 nasdaqhe 阅读(18) 评论(0) 编辑

代码
        #region 判断Url参数是否UTF8编码
        
public static bool IsUTF8(string url)
        {
            
byte[] buf = GetUrlCodingToBytes(url);
            
return IsTextUTF8(buf);
        }
        
private static bool IsTextUTF8(byte[] buf)
        {
            
int i;
            
byte cOctets = 0// octets to go in this UTF-8 encoded character  
            bool bAllAscii = true;
            
long iLen = buf.Length;
            
for (i = 0; i < iLen; i++)
            {
                
if ((buf[i] & 0x80!= 0) bAllAscii = false;

                
if (cOctets == 0)
                {
                    
if (buf[i] >= 0x80)
                    {
                        
do
                        {
                            buf[i] 
<<= 1;
                            cOctets
++;
                        }
                        
while ((buf[i] & 0x80!= 0);

                        cOctets
--;
                        
if (cOctets != 2)
                            
return false;
                    }
                }
                
else
                {
                    
if ((buf[i] & 0xC0!= 0x80)
                        
return false;
                    cOctets
--;
                }
            }
            
if (cOctets > 0)
                
return false;
            
if (bAllAscii)
                
return false;
            
return true;
        }
        
private static byte[] GetUrlCodingToBytes(string url)
        {
            StringBuilder sb 
= new StringBuilder();

            
int i = url.IndexOf('%');
            
while (i >= 0)
            {
                
if (url.Length < i + 3)
                {
                    
break;
                }
                sb.Append(url.Substring(i, 
3));
                url 
= url.Substring(i + 3);
                i 
= url.IndexOf('%');
            }

            
string urlCoding = sb.ToString();
            
if (string.IsNullOrEmpty(urlCoding))
                
return new byte[0];

            urlCoding 
= urlCoding.Replace("%"string.Empty);
            
int len = urlCoding.Length / 2;
            
byte[] result = new byte[len];
            len 
*= 2;
            
for (int index = 0; index < len; index++)
            {
                
string s = urlCoding.Substring(index, 2);
                
int b = int.Parse(s, System.Globalization.NumberStyles.HexNumber);
                result[index 
/ 2= (byte)b;
                index
++;
            }
            
return result;
        }
        
#endregion 判断Url参数是否UTF8编码

UTF-8编码规则参考

http://blog.csdn.net/sandyen/archive/2006/08/23/1108168.aspx

 上面代码是网络上找的,不过存在大部分不能识别的情况,后根据对于中文,UTF8 一定编码成 3 字节,这个原则

 修改了一下,现在大部分情况下都能正确识别

 

posted @ 2010-12-23 11:16 nasdaqhe 阅读(71) 评论(0) 编辑

2010年12月15日

只有mdf 文件,没有日志文件附加数据库的方法
EXEC sp_attach_single_file_db @dbname= 'test'
        , 
@physname=  N'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test.mdf'

 

posted @ 2010-12-15 22:41 nasdaqhe 阅读(18) 评论(0) 编辑

2010年12月1日

posted @ 2010-12-01 08:42 nasdaqhe 阅读(59) 评论(0) 编辑

2010年6月17日

摘要: 用JavaScript玩转游戏物理(一)运动学模拟与粒子系统http://www.cnblogs.com/miloyip/archive/2010/06/14/Kinematics_ParticleSystem.html阅读全文

posted @ 2010-06-17 21:59 nasdaqhe 阅读(74) 评论(0) 编辑

2010年6月13日

摘要: 开启SSHCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->sudoapt-getinstallopenssh-server列出分区信息Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->sudofdisk-l挂载分区Code highlighting produced by Actipro Co阅读全文

posted @ 2010-06-13 21:01 nasdaqhe 阅读(22) 评论(0) 编辑