手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:javascript

Minify的简单介绍

上篇从老王的博客里抓了点东西,在文末我提到了minify,然后我又从nio的博客中找到minify的资料,同样贴给大家,具体的英文更新,还是可以从:http://code.google.com/p/minify/来进行获取,下面的是nio的翻译。。。

原文网址:http://nio.infor96.com/archives/862

内容如下:

Minify 是使用 PHP5 开发的用于合并压缩 js/css 文件的应用程序。合并压缩之后的结果可通过 HTTP gzip/deflate 及一些相关头,优化客户端缓存。可参考 Yahoo 的 Rules for High Performance Web Sites

Minify 的安装使用很简单,下载最新版本,解压,将 min 目录复制到发布目录下,然后访问 http://example.com/min/,在显示的界面中加入你想合并压缩的 js/css 路径,点击 'Update' 之后会为你生成一个 url,如:

http://localhost/min/b=googletesting/js&f=mootools.js,iAction.js,iAjax.js,global.js

接下来你就可以将这个 url 放到你的页面中了。这样可以使请求数减少,传输的字节数也小了很多。而且 Minify 支持服务器端 cache,即将合并压缩的结果 cache 到服务器端文件中,下次访问就不需要再重新做合并压缩的操作了。如果需要组合的文件很多,url 就会变得很长,Minify 支持 group,可以将这些文件分组,这样 url 中只需指定 g=group名字 就可以了。

总之,Minify 很实用 :)


以下是最新更新的内容:

Version 2.1.0 (2008-09-18)

  • "min" default application for quick deployment
  • Minify URI Builder app & bookmarklet for quickly creating minify URIs
  • Relative URIs in CSS file are fixed automatically by default
  • "debug" mode for revealing original line #s in combined files
  • Better IIS support
  • Improved minifier classes:
    • JS: preserves IE conditional comments
    • CSS: smaller output, preserves more hacks and valid CSS syntax, shorter line lengths, other bug fixes
    • HTML: smaller output, shorter line lengths, other bug fixes
  • Default Cache-Control: max-age of 30 minutes
  • Conditional GETs supported even when max-age sent
  • Experimental memcache cache class (default is files)
  • Minify_Cache_File has flock()s (by default)
  • Workaround for Windows mtime reporting bug

 

 

Tags: minify, php, javascript

FormValidator又升级了

jQuery里面这个插件应该用的是相对比较多的,最起码在提交表单的时候方便了不少,不需要再自己一个一个的根据条件写JS,主要还是为了方便。。。

这次更新的内容有:

这次的更新内容摘要如下:

1、为compareValidator里的datatype属性增加新的类型:date、datetime。
那么到目前为止,插件支持4种常类型:"string"、"number"、"date"、"datetime",默认值为"string"

2、为inputValidator里的属性type增加类型为date、datetime,min和max必须为string类型,会自动转换
"size":表示比较长度 ,默认值
"number":数值型比较
"string":字符型比较
"date":短日期类型
"datetime":长日期类型

3、为initConfig增加属性errorfocus,表示发生错误的时候,第一个出错控件是否获得焦点。默认获得焦点。

4、initConfig增加属性forcevalid属性;formValidator增加forcevalid属性,表示是否一直输入正确为止才允许离开焦点。
initConfig的forcevalid优先等级最高,即全局配置;而formValidator里的forcevalid是局部设置。

5、initConfig增加属性wideword,默认为false,表示是否把一个汉字当做一个长度的参数。
请见demo1最上面的按钮演示。

6、增加ajaxValidator对password控件的支持

7、修正升级中出现的一些bug,现都已修复
在升级的过程中,造成公用一个tip的功能丢失,现已修复。
bug描述:只显示第一个控件的信息,后面的控件正确与否都不理睬。
ajaxValidator的一些状态显示bug

固定发布(下载)页面:
http://www.cnblogs.com/wzmaodong/archive/2008/01/11/1034901.html

有兴趣的朋友可以去订阅作者的博客,以后就可以第一时间知道他的更新。

Tags: jquery, formvalidator, update

叫卖fans123..com和fans123.net

这两个域名在我身边很久了,当初的一些想法最后都没有做。在征得团队成员的同意后,决定出售这两个域名。

有需要的可以在此留言,或者加我QQ或者MSN等 。。。
QQ:19129540
msn:goukixiao@hotmail.com,学学坏人,用全角,呵呵

Tags: 玉米, 域名, 出售, fans123

使用CURL函数发送数据时的注意事项

PHP函数库里面,提到CURL,恐怕很多人都会翘起大拇指吧,确实,这个函数库太牛叉了

CURL其实是调用的CURL的lib,随着PHP版本的升高,curl所需的lib版本也随之提高。

关于CURL所必须的类库和安装说明,手册上有详细介绍:

XML/HTML代码
  1. Requirements  
  2.   
  3. In order to use PHP's cURL functions you need to install the libcurl package. PHP requires that you use libcurl 7.0.2-beta or higher. In PHP 4.2.3, you will need libcurl version 7.9.0 or higher. From PHP 4.3.0, you will need a libcurl version that's 7.9.8 or higher. PHP 5.0.0 requires a libcurl version 7.10.5 or greater.  
  4.   
  5. Installation  
  6.   
  7. To use PHP's cURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use cURL for URL streams --with-curlwrappers.   
  8.   
  9. Note to Win32 Users: In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH.   
  10. You don't need libcurl.dll from the cURL site.   

然后在使用的时候也很方便,只需要初始化一下,设置一下postfields或者GET啥啥的,最后exec一下就行了。关键是别忘了close.

例子代码如下:

PHP代码
  1. $ch = curl_init("http://www.example.com/");  
  2. $fp = fopen("example_homepage.txt""w");  
  3.   
  4. curl_setopt($ch, CURLOPT_FILE, $fp);  
  5. curl_setopt($ch, CURLOPT_HEADER, 0);  
  6.   
  7. curl_exec($ch);  
  8. curl_close($ch);  
  9. fclose($fp);  

以上例子代码有点特殊,是因为他把网页内容进行了下载,同时生成一个文件。这是默认调用GET的方法。

其实,CURL更多的是用来处理POST数据、上传文件等功能

例子如下:

PHP代码
  1. <?   
  2. /*  
  3. * Author: Ron  
  4. * Released: August 4, 2007  
  5. * Description: An example of the disguise_curl() function in order to grab contents from a website while remaining fully camouflaged by using a fake user agent and fake headers.  
  6. */   
  7.   
  8. $url = 'http://www.ericgiguere.com/tools/http-header-viewer.html';   
  9.   
  10. // disguises the curl using fake headers and a fake user agent.   
  11. function disguise_curl($url)   
  12. {   
  13.   $curl = curl_init();   
  14.   
  15.   // Setup headers - I used the same headers from Firefox version 2.0.0.6   
  16.   // below was split up because php.net said the line was too long. :/   
  17.   $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";   
  18.   $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";   
  19.   $header[] = "Cache-Control: max-age=0";   
  20.   $header[] = "Connection: keep-alive";   
  21.   $header[] = "Keep-Alive: 300";   
  22.   $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";   
  23.   $header[] = "Accept-Language: en-us,en;q=0.5";   
  24.   $header[] = "Pragma: "// browsers keep this blank.   
  25.   
  26.   curl_setopt($curl, CURLOPT_URL, $url);   
  27.   curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');   
  28.   curl_setopt($curl, CURLOPT_HTTPHEADER, $header);   
  29.   curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');   
  30.   curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');   
  31.   curl_setopt($curl, CURLOPT_AUTOREFERER, true);   
  32.   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   
  33.   curl_setopt($curl, CURLOPT_TIMEOUT, 10);   
  34.   
  35.   $html = curl_exec($curl); // execute the curl command   
  36.   curl_close($curl); // close the connection   
  37.   
  38.   return $html// and finally, return $html   
  39. }   
  40.   
  41. // uses the function and displays the text off the website   
  42. $text = disguise_curl($url);   
  43. echo $text;   
  44. ?>   

上面是一个比较完整的实现。特别需要注意的是header头部的发送,最初看手册的时候,我一以为CURLOPT_HTTPHEADER所需的数组是键值对应的,即:

PHP代码
  1. $header = array('Keep-Alive'=>'300');  

现实的残酷告诉我,不应该这么用,而是象上面的例子那样,每条header为数组的一个记录。

切记切记啊

Tags: curl, curlopt, httpheader, libcurl, charset

对于n个条件中有大于等于或小于m个条件成立时符合要求的sql 条件语句的写法

假设的应用场景 

我假定博客园要在首页为群组开辟一块空间,推广小组,小组能在首页显示的条件有四个:

1.       页面点击量大于10w

2.       小组人数大于1000

3.       小组帖子数大于10000

4.       小组在2007年之前创建

现在假定4个条件都满足的小组只有两个,太少了,推广位可以推广10个小组;这时候运营人员要求这4个条件中满足3个但是第4个条件不满足的小组算符合条件的小组,如果4个条件都满足就认为这个小组太火了,不需要在首页推广它了。业务逻辑想清楚了,下一步就该写代码了,数据逻辑层的代码的任务假定交给我了,我要考虑满足4个条件中3个成立的sql怎么写。

为了叙事方便,我们假如小组表的名字为Group,相关的条件字段是Pv,UserCount,PostCount,CreateTime:分别表示小组的点击量,人数,帖子数,创建时间

我来写sql语句,上面的四个条件满足至少3个,有多少种情况呢?这是一个组合问题,一共有多少种的公式我已经忘记了,我要根据感觉写写看:

SELECT * FROM Group
WHERE  (Pv>100000 AND UserCount>1000 AND PostCount>10000 AND CreateTime > 20070101
OR (Pv>100000 AND UserCount>1000 AND PostCount<10000 AND CreateTime < 20070101)
OR (Pv>100000 AND UserCount<1000 AND PostCount>10000 AND CreateTime < 20070101)

这个Sql语句条件还行,但是我们的题目是n个条件m个条件成立,如果多了还这么写,恐怕就很累了,能不能改进呢?答案是肯定的,要不我就不写这篇随笔了,呵呵

SELECT * FROM Group
WHERE 
(
CASE Pv WHEN Pv>100000 THEN 1 ELSE 0 END--这是PV的条件成立则为1,否则为0
+(CASE UserCount WHEN UserCount > 1000 THEN 1 ELSE 0 END--用户数条件
+(CASE PostCount WHEN PostCount > 10000 THEN 1 ELSE 0 END--帖子数条件
+(CASE CreateTime WHEN CreateTime < 20070101 THEN 1 ELSE 0 END--时间条件
= 3

如果上面的三个表达式加起来值是3就说明恰好满足三个条件,如果是两个条件就是等于2,如果扩展为n个条件m个条件成立也很容易写,很容易维护、修改。 

这是一个sql条件语句的技巧,希望对你有用。

本文假设的场景纯属虚设,请勿遐想。J

 

原文地址:http://www.cnblogs.com/yukaizhao/archive/2008/11/14/sql_condition_m_n.html

PS:

顺便说明一下,在mysql中也支持这样的用法(4我没有试过,但是5是支持这样的用法的。)虽然这样的用法比较容易写和维护及修改,但看上去还是有点妖。而且,效率不一定能保证。

Tags: 数据库, 条件查询, where

Records:341234567