易栈网-膘叔

浏览模式: 标准 | 列表 | 图文

一个疏忽引发的血案

这是一个PHP的函数,可以把相对路径转为绝对路径。比如可以把http://www.neatstudio.com/archive/../upload/xxx.jpg,转换成http://www.neatstudio.com/upload/xxx.jpg

function getRealUrl($url) {
$path = parse_url($url, PHP_URL_PATH);
$patharr = explode("/", $path);
$newarr = array();
$i = 0;
foreach ($patharr as $k => $val) {
if ($k != 0 && !$val) {
continue;
}
if ($val == '..' && count($newarr) > 1) {
unset($newarr[$i - 1]);
$i--;
continue;
}
$newarr[$i] = $val;
$i++;
}
$newpath = join("/", $newarr);
return str_replace($path, $newpath, $url);
}

正常情况下,都没什么问题。但某一天,居然遇到了这样的网址:http://neatstudio.com/xxx/xxx/../0/abc.jpg,于是就出错了,返回成http://neatstudio.com/xxx/abc.jpg
细心的朋友可能发现了上面的问题,/0这个目录不见了。这是为什么呢??

居然是因为第7行 ,我对$val的判断是!$val。。。它认为0目录是不为真就跳过了。TNND,所以我改成了$val == '',真纠结。

粗心啊(请不要纠结上面的代码。花10分钟写的东西,质量不高是肯定的。)

几个无限分类的设计

之前在博客里贴过无限分类的介绍,那是官方的例子,但上次在给同事们做介绍的时候,却发现官方的网站已经打不开了。所幸,又找到了一篇,好象这个才是原文?
原文来自:http://www.vbmysql.com/articles/database-design/managing-hierarchical-data-in-mysql
为了这次保证所有的数据都能够记录下来而不是再被茫茫的互联网淹没,所以我做了备份。
00c112a76cd8d89fdbb6ffe35615060e
但同样的,我也再次复制一部分的内容下来,好象是说这种无限分类的效率,在被其他项目查询的时候是最高的,但CRUD的时候就有点纠结。
OK,上主菜:

The Nested Set Model

What I would like to focus on in this article is a different approach, commonly referred to as the Nested Set Model. In the Nested Set Model, we can look at our hierarchy in a new way, not as nodes and lines, but as nested containers. Try picturing our electronics categories this way:

Nested Categories

Notice how our hierarchy is still maintained, as parent categories envelop their children.We represent this form of hierarchy in a table through the use of left and right values to represent the nesting of our nodes:

CREATE TABLE nested_category (         category_id INT AUTO_INCREMENT PRIMARY KEY,         name VARCHAR(20) NOT NULL,         lft INT NOT NULL,         rgt INT NOT NULL );  INSERT INTO nested_category VALUES(1,'ELECTRONICS',1,20),(2,'TELEVISIONS',2,9),(3,'TUBE',3,4),  (4,'LCD',5,6),(5,'PLASMA',7,8),(6,'PORTABLE ELECTRONICS',10,19),(7,'MP3 PLAYERS',11,14),(8,'FLASH',12,13),  (9,'CD PLAYERS',15,16),(10,'2 WAY RADIOS',17,18);  SELECT * FROM nested_category ORDER BY category_id;  +-------------+----------------------+-----+-----+ | category_id | name                 | lft | rgt | +-------------+----------------------+-----+-----+ |           1 | ELECTRONICS          |   1 |  20 | |           2 | TELEVISIONS          |   2 |   9 | |           3 | TUBE                 |   3 |   4 | |           4 | LCD                  |   5 |   6 | |           5 | PLASMA               |   7 |   8 | |           6 | PORTABLE ELECTRONICS |  10 |  19 | |           7 | MP3 PLAYERS          |  11 |  14 | |           8 | FLASH                |  12 |  13 | |           9 | CD PLAYERS           |  15 |  16 | |          10 | 2 WAY RADIOS         |  17 |  18 | +-------------+----------------------+-----+-----+

We use lft and rgt because left and right are reserved words in MySQL, see http://dev.mysql.com/doc/mysql/en/reserved-words.html for the full list of reserved words.

So how do we determine left and right values? We start numbering at the leftmost side of the outer node and continue to the right:

Numbering edges

This design can be applied to a typical tree as well:

Numbered Tree

When working with a tree, we work from left to right, one layer at a time, descending to each node’s children before assigning a right-hand number and moving on to the right. This approach is called the modified preorder tree traversal algorithm.

因为我已经在压缩包里做了备份,所以我图片就引用外站的了。

GitHub管理运营之道:时间就是胡扯

看到本文时突然想起以前单位的一位美工,每天都是下午1点上班,晚上9、10点回家,他说这样对他来说效率最好。
由于他的工作和其他人的工作没有过多的配合等,所以领导也就默认了这样的考勤时间,只是从那之后就再也没有看到过类似的情况了。
于是本文就特别让我感慨,原文来自:http://news.csdn.net/a/20110817/303173.html:

八小时工作日,在国内很多IT公司是铁定的工作制度。这一制度是否有利于开发者高效地工作呢?除此之外,灵活的工作制度对开发者工作效率又会有怎样的影响?GitHub工程师Zach Holman针对GitHub的运营管理,写了一篇博文《How GitHub Works: Hours are Bullshit》,文中分享了GitHub的运营管理之道,现把该文进行了编译,译文如下:

俗话说,时间就是金钱,速度越快越好。时间越多越好。

时间就是废话

在很多工业企业中,时间是决定生产效率的一个主要因素,但对于GitHub不是。在一个创业公司中,你不可能在一个问题上投入更多的时间,以期得到彻底解决。代码才是努力的方向。你需要具有正确的思维模式,以便创造出高质量的代码。

回想最近一次令你印象深刻或生气的事。你的工作效率如何?回想一下你最近真正高效的一次经历。代码从指间如飞般产出。当你具有正确的思维模式时,某一天高效的代码编程,可以胜过你一周受挫的编程工作。

我们希望员工尽可能在这一状态下工作。限定员工在办公室中办公的时间会影响他们的工作状态。如果要求我在9点之前必须到达办公室,我是很难保持这种高效状态的,但对于在GitHub的一半员工来说,上午可能是他们工作状态最好的时间。

允许员工更加灵活的工作时间,可以营造一个令员工兴奋的工作环境。在这个环境中,他们可以工作更长的时间,并一直保持高效的工作效率。

一天的工作

在GitHub,每个人的一天的工作时间安排是不同的。同样我的每天也是不同的,下面是一个大概的时间安排:

1.上午十点钟左右起床;

2.坐公共汽车去上班,并在中午或下午一点去吃午饭;

3.从下午一点找个地方工作,下午六点到九点在办公室里工作;

4.之后回家,并在家中沙发上工作或休息到早上两点。有时也会和同事出去吃饭。

有的同事可能在上午7点就来到办公室工作;也有的在下午3点才来。有的同事觉得在家工作比较高效。如果员工不喜欢在办公室工作,他们可以不用每天来公司(虽然大多数情况下,每个人都会来公司)。

我们一天的工作时间为什么如此“松散”,原因有二,一是工作在宽松的环境中,可以使我们在我们喜欢的时间和地方工作;二是我们希望创造一个可以使员工最高效率工作的工作环境。因为每个人高效工作的时间都不相同,所以我们不会强迫任何一个人。

限制性工作

现在GitHub有35名员工,并且还在增长中。这个方法带来了很好的效果。但是管理者仍喜欢固定的工作时间,原因有一:他们有一种错觉,认为时间是衡量员工工作的标准。

如果对工作时间很难把握,你需要寻找其他的衡量方法。他们的代码写得很出色吗?他们把Bug都处理完了吗?他们全身心地投入到工作中了吗?工作上更大的灵活性是否激发了他们工作的积极性?

对此很难做出定性的判断,但是相比起“在工作日的十小时内把这件事做好”,上面这些方法更有价值。因为当你用时间来衡量工作时,他们的工作就会变成更多的时间编写更少的代码。

原文链接:How GitHub Works: Hours are Bullshit

------------------------
如果你是BOSS,你又会怎么样对你的员工呢?即使真的象上文所说的,其实也不一定就好,毕竟如果多人工作内容有交互,怎么更好的合理安排时间才是最痛苦的。

他还活着?Foxmail 7.0.1.76 beta出来了

他还活着?Foxmail 7.0.1.76 beta出来了

说实话,自从它到了腾讯后变成腾讯的软件后,我一直以为他就那样的死去了。
从很久以前,我就一直在用它,6.0给我带来的惊喜已经逐渐离我远去了。从6.0到6.5,从6.5到7.0,你以为你是玻璃渣?几年才出一个?
不过WEB mail这一块还是有更新的,所以我一直以为6.5不会再出新版了。所以我才觉得那样的意外。。。
http://fox.foxmail.com.cn/index.htm
官方有介绍了,这次的新版的界面超象outlook呀。而且也全面支持Exchange了
92979d76299e5ea0d3b94dd3220cea48
主要是由于一些计划任务在用,而且有时候从苹果里发出来的邮件中内嵌图片的,我居然用foxmail收下来是显示不了的。而又占用了空间,TNND,所以暂时我目前已经不在使用了
有兴趣的可以尝试一下下

Yii + Zend_Feed

Yii + Zend_Feed

YII是一个PHP框架。
ZendFramework也是一个PHP框架
在Yii里配置ZF框架,刷刷的就一个RSS阅读器就出来了。
代码很简单,把Zend整合COPY到protected/extensions目录下
在控制器的init方法里加入:
Yii::import("ext.*");
require_once("Zend_Feed_Reader.php");

然后在需要的方法里加入
$feed = Zend_Feed_Reader::import("http://neatstudio.com/rss.php");
这样就创建了一个读的对象了。然后。。。。。
你懂的:

$data = array(
'title' => $feed->getTitle(),
'link' => $feed->getLink(),
'dateModified' => $feed->getDateModified(),
'description' => $feed->getDescription(),
'language' => $feed->getLanguage(),
'entries' => array(),
);

foreach ($feed as $entry) {
$edata = array(
'title' => $entry->getTitle(),
'description' => $entry->getDescription(),
'dateModified' => $entry->getDateModified(),
'authors' => $entry->getAuthors(),
'link' => $entry->getLink(),
'content' => $entry->getContent()
);
$data['entries'][] = $edata;
}
print_r($data);

就这样,一个刚刚的RSS阅读器就出来了。
当然,它没有缓存,没有这没有那的,不过,都解析完了,剩下的功能还会远吗?

pdf转换epub格式软件下载

pdf转换epub格式软件下载

看上这个软件是因为NOOK下面读PDF还是会有点小问题,但EPUB对中文的默认支持又不好,真TMD纠结。
软件还没有试用,不过能够放出来,估计问题不会特别大
PDF to EPUB Converter是一个将PDF转换为EPUB格式的软件,有文本和图片两种转换模式,支持编辑EPUB信息,包括名称、作者、ISBN、发行商、图片 类别与注释等。EPUB是一种电子图书标准,其文字内容可以根据阅读设备的不同而以最佳阅读方式显示,iPad、iPhone、Android等均支持 EPUB图书。
4d3e007170e1203569a1e9ec9b103b43
软件有点大,这个链接可以下载:http://www.weste.net/download.php?a_k=XAsPAlIBCxBUXAxCEkMNTRlDHgYDAUoACQ4YAAgJA05UR0FPHVQMQT9HAAtXFURfEEINBgEFV1ZWWwdRUEMPEQgHCQRKCAkAHFBUBEgEAURbCwA%3D
当然,如果不行,你看到这个网址没,点进去搜索一下就OK了。

我只是纯备份,还没有测试(所以也不知道有没有病毒啊)

JavaScript类型总览(图) --来自周爱民的博客

JavaScript类型总览(图) --来自周爱民的博客

一张图,来自周爱民的博客。
原文地址是:http://blog.csdn.net/aimingoo/article/details/6676530
用周爱民的话来说,这张图是:来自于《JavaScript语言精髓与编程实践》第三章P184页。
第二版说是会改,那么,在没改之前可以参考一下:
9ca422e3e6a343a28b3becab3a17d398
文末还提到了一些补充一下图中用到的概念:

1、内置(Build-in)对象与原生(Naitve)对象的区别在于:前者总是在引擎初始化阶段就被创建好的对象,是后者的一个子集;而后者包括了一些在运行过程中动态创建的对象。

2、引擎扩展对象是一个并不太大的集合,一般来说比较确定,它们也属于引擎的原生对象(但不属于ECMA规范的原生对象)。

3、宿主对象不是引擎的原生对象,而是由宿主框架通过某种机制注册到JavaScript引擎中的对象。

4、一些宿主会把自己提供的对象/构造器也称为“原生对象”,例如Internet Explorer 7就把它提供的XMLHttpRequest()称为原生的——与此相对的是在它的更早先版本中通过“new ActiveXObject('Microsoft.XMLHTTP')”这样的方法创建的对象。这种情况下,读者应注意到“宿主的原生对象”与“引擎的原生对象”之间的差异。

HTML5拖放上传

html5中有一个特性就是以前一直常说的拖放上传,其实这个功能要实现的话真的不太难,但我对于DOM的操作并不是特别了解,因此我找了一些资料做备份
1、xheditor中的代码
2、html5的一些教程

xheditor中的代码很少,只有区区几行:

jBody.bind('dragenter dragover',function(ev){var types;if((types=ev.originalEvent.dataTransfer.types)&&$.inArray('Files', types)!==-1)return false;}).bind('drop',function(ev){
var dataTransfer=ev.originalEvent.dataTransfer,fileList;
if(dataTransfer&&(fileList=dataTransfer.files)&&fileList.length>0){
var i,cmd,arrCmd=['Link','Img','Flash','Media'],arrExt=[],strExt;
for(i in arrCmd){
cmd=arrCmd[i];
if(settings['up'+cmd+'Url']&&settings['up'+cmd+'Url'].match(/^[^!].*/i))arrExt.push(cmd+':,'+settings['up'+cmd+'Ext']);//允许上传
}
if(arrExt.length===0)return false;//禁止上传
else strExt=arrExt.join(',');
function getCmd(fileList){
var match,fileExt,cmd;
for(i=0;i<fileList.length;i++){
fileExt=fileList[i].fileName.replace(/.+\./,'');
if(match=strExt.match(new RegExp('(\\w+):[^:]*,'+fileExt+'(?:,|$)','i'))){
if(!cmd)cmd=match[1];
else if(cmd!==match[1])return 2;
}
else return 1;
}
return cmd;
}
cmd=getCmd(fileList);
if(cmd===1)alert('上传文件的扩展名必需为:'+strExt.replace(/\w+:,/g,''));
else if(cmd===2)alert('每次只能拖放上传同一类型文件');
else if(cmd){
_this.startUpload(fileList,settings['up'+cmd+'Url'],'*',function(arrMsg){
var arrUrl=[],msg,onUpload=settings.onUpload;
if(onUpload)onUpload(arrMsg);//用户上传回调
for(i in arrMsg){
msg=arrMsg[i];
url=is(msg,'string')?msg:msg.url;
if(url.substr(0,1)==='!')url=url.substr(1);
arrUrl.push(url);
}
_this.exec(cmd);
$('#xhe'+cmd+'Url').val(arrUrl.join(' '));
$('#xheSave').click();
});
}
return false;
}
});

也有这样的:HTML5拖放(Drag&Drop)API详细介绍和示例,当然这里我就不多贴代码了。不过文中最后一段是告诉我们有哪些事件可以用:

可以使用的新事件一共有这些:

dragstart
A drag has been initiated, with the dragged element as the event target.
drag
The mouse has moved, with the dragged element as the event target.
dragenter
The dragged element has been moved into a drop listener, with the drop listener element as the event target.
dragover
The dragged element has been moved over a drop listener, with the drop listener element as the event target. Since the default behavior is to cancel drops, returning false or calling preventDefault() in the event handler indicates that a drop is allowed here.
dragleave
The dragged element has been moved out of a drop listener, with the drop listener element as the event target.
drop
The dragged element has been successfully dropped on a drop listener, with the drop listener element as the event target.
dragend
A drag has been ended, successfully or not, with the dragged element as the event target.

并且注意能够被拖拽的元素一定要有这个属性:draggable=”true”

在web上面拖放一直以来都是个难题(strange beast),但是至少现在我们有一堆丰富的API了…. 所以也许这个方式会开始大行其道呢?

苹果官方:Introduction to WebKit DOM Programming Topics

苹果官方:Introduction to WebKit DOM Programming Topics

这是一篇来自苹果官方的教程,原来我也没想到过,居然可以用JS来调用Object-C中的东东。其实想想,这应该是可以,要知道,象maxthon这些浏览器,可就是早就能够调用他们的核心组件了,当然,也是用JS的。firefox也是类似。。。所以Safari应该也是可以支持的。
官方文章地址是:http://developer.apple.com/library/mac/#documentation/AppleApplications/Conceptual/SafariJSProgTopics/WebKitJavaScript.html

看看他们是怎么写的,
Important: This is a preliminary document. Although it has been reviewed for technical accuracy, it is not final. Apple is supplying this information to help you adopt the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be vetted against final documentation. For information about updates to this and other developer documentation, you can check the ADC Reference Library Revision List. To receive notification of documentation updates, you can sign up for a free Apple Developer Connection Online membership and receive the bi-weekly ADC News e-mail newsletter. See http://developer.apple.com/products/for more details about ADC membership.)

还有。。。

Who Should Read This Document?

This document is designed for a number of different audiences:

  • If you are a web content developer—developing web sites and embedded JavaScript applications—you should read about Safari’s JavaScript support and how scripts operate within WebKit-based applications.

  • If you are a Cocoa and WebKit developer, you should read about how to integrate JavaScript into your WebKit views and how to enhance your user experience in doing so.

  • If you are a Dashboard developer, you should read about integrating JavaScript into your widgets to provide a better user experience and more advanced features to your users.

Organization of This Document

The topic contains the following articles:

See Also

  • Safari HTML Reference provides descriptions of HTML tags, attributes, and other markup.

  • Safari CSS Reference provides descriptions of CSS properties and constants.

  • Safari Web Content Guide provides information about designing web content for iPhone.

  • Dashboard Programming Topics provides information on the technologies available to you when creating a Dashboard widget. Additional Dashboard documents and sample code can be found in the Reference Library > Apple Applications > Dashboard.

  • Apple JavaScript Coding Guidelines provides general tips about the JavaScript programming language.

  • The Reference Library > Apple Applications > Safari section of the ADC Reference Library provides useful information on WebKit, the technology that provides Apple’s JavaScript runtime.

果然还是官方的资料最多,NND,平时搜点资料都搜不到,还是官方给的方案最多啊。