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

为debian增加apt-add-repository功能

ubuntu下面有一个很不错的功能,它能够使你很方便 的添加ppa的源,那就是apt-add-repository
在我之前写的一篇博客里就有介绍此功能(关于gearman的),但在debian系统上就无法适用,因为debian下没有此功能
于是找了ubuntu下的apt-add-repository的代码,cp了一份到debian下面,但不能运行。所以google了一下,发现这么一段代码就OK了:

XML/HTML代码
  1. #!/bin/bash   
  2. if [ $# -eq 1 ]   
  3. then   
  4.     ppa_name=`echo "$1" | cut -d":" -f2 -s`   
  5.     if [ -z "$ppa_name" ]   
  6.     then   
  7.         echo "PPA name not found"   
  8.         echo "Utility to add PPA repositories in your debian machine"   
  9.         echo "$0 ppa:user/ppa-name"   
  10.     else   
  11.         echo "$ppa_name"   
  12.         echo "deb http://ppa.launchpad.net/$ppa_name/ubuntu lucid main" >> /etc/apt/sources.list   
  13.         apt-get update >> /dev/null 2> /tmp/apt_add_key.txt   
  14.         key=`cat /tmp/apt_add_key.txt | cut -d":" -f6 | cut -d" " -f3`   
  15.         apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key   
  16.         rm -rf /tmp/apt_add_key.txt   
  17.     fi   
  18. else   
  19.     echo "Utility to add PPA repositories in your debian machine"   
  20.     echo "$0 ppa:user/ppa-name"   
  21. fi   

将这段内容存成apt-add-repository,然后cp到/usr/bin目录下,并且chmod +x 这个文件,让它有可执行的权限。
再接着使用apt-add-repository 来添加源就OK了
这个自定义的版本,在添加完源后,还会将source.list进行了修改。比ubuntu还人性化。。
参考:
1.http://cptbtptp.blog.51cto.com/3228046/620036
2.http://jolin.2001.blog.163.com/blog/static/89912172011485354567/
两篇内容细看,其实就是一样的。。

Tags: debian, ubuntu, apt, ppa

转:HTML 格式的邮件如何定义 CSS

转这篇文章之前,先介绍一下"SEGMENTFAULT(http://segmentfault.com/)",或许国内已经有很多人知道这个网站了,但毕竟它还是一个新站,看趋势是想做成stackflow之类的国内站,他这么说自己的网站:

XML/HTML代码
  1. 在 Google 搜索技术问题时突然发现从某段时间开始,所有的问题都被指 向 StackOverflow 这个网站了。而且这个网站的问题和答案质量都很高。但是有一点我很烦恼,没有中文,虽然对技术人员来说看懂英文是最基本 的,但是如果能有一个类似的中文问答社区,对于技术的交流是非常有益的。  
  2.   
  3. 因此,我们借鉴了 StackOverflow 的评分机制,搭建了这个网站。最初的想法很简单:我们在搜索技术问题时,能有中文的优质答案出现在搜索结果里。  

上原文吧:
问:HTML 格式的邮件如何定义 CSS
内容:

按照写网页的习惯,的把 css 写在 header 里,样式在 Outlook 和 Mail 客户端都能够正常显示。但是,发现在 Gmail 的 Web 界面上,移除了 body 及其外部的所有代码。
Email HTML 如下:

XML/HTML代码
  1. <!doctype html>  
  2. <head>  
  3.     <meta charset="UTF-8" />  
  4.     <style type="text/css">  
  5.         .title { color: red }      
  6.     </style>  
  7. </head>  
  8. <body>  
  9.     <h2 class="title">Email title here</h2>  
  10. </body>  
  11. </html>  

 

邮件发出后,在 Gmail 里看到的邮件内容代码只剩下了:
XML/HTML代码
  1. <h2 class="title">Email title here</h2>  
如果想在 Gmail 里正确的显示样式,目前只发现下面的方式才显示正常:
XML/HTML代码
  1. <h2  style="color: red">Email title here</h2>
难道,整封邮件只能这样实现了么,有别的方法吗?

回答:

1、经过google搜索,发现gmail目前支持inline的css方式。

看来只能悲剧的inline了。

2、国外有篇博客讲了怎样写HTML邮件:<HTML Email Coding 101> http://litmus.com/blog/html-email-cod...

不仅仅是CSS。我看过,写得很好,图文并茂,你可以看看

Tags: segmentfault, typecho

rework 摘录一

这是其中一段,事实上在很久以前就知道了,但最终都无法改变
里面的一小段说的很有意思,那就是,会议会衍生会议,。。。。

OK,上原文:

会议有毒

会议是最糟糕的打断方式。原因是:

通常会议只是文字和抽象的内容,没有实质。

通常会议每分钟只传达出极为少的信息。

人们在会议中容易跑题堪比暴风雪里的芝加哥出租车。

会议要求做充分的准备,但是大多数人难以做到。

频繁的提出模糊的议程而没有人能真的清楚目标是什么。

常常会出现至少一个傻瓜不可避免的,毫无意义的浪费大家时间。

会议会繁殖。一次会议会导致另外一次,再生出下一次......

不幸的是会议典型的时间表就像电视节目。

你腾出 30 分钟或一个小时因为那是软件安排的行时间表( 你决不会看见任何人安排 7 分钟时间和 Outlook 开会)。太糟了。如果只是花 7 分钟时间就能完成会议目标,那这就是你所要花的所有时间。别把 7 分钟拖到 30 分钟。

想想看,会议所花费的真实时间是惊人的。 假如你准备安排一次会议持续一个小时,你请了 10 个人到场。那确实是 10 个小时的会议,不是一小时会议。你用 10 小时的生产力换来一个小时的会议时间。也有可能花超过 15 小时的时间,因为要停下你正在做的事情,需要精神转换, 去哪里见什么人,然后再重新开始预先在做的事情。

花 10 小时生产力去换 1 个小时的会议可以吗?有时,也许可以。但这样真的不划算。 就基于付出的来说, 这种规模的会议很快就变成一种不利因素而不是有力因素。 想想你浪费的时间,值得吗?

如果你执意要聚一下,试着坚持以下原则会让你的会议有成效:

用计时器。当它响起,会议结束。句号。

尽量减少与会人员。

保持清楚的议程。

开篇点题。

就地解决。指出实际问题,提出实质改变。

作出结论,找个靠谱的人去执行。

Tags: rework

PHP的XSS攻击过滤函数

XSS攻击在最近很是流行,往往在某段代码里一不小心就会被人放上XSS攻击的代码,看到国外有人写上了函数,咱也偷偷懒,悄悄的贴上来。。。
原文如下:
The goal of this function is to be a generic function that can be used to parse almost any input and render it XSS safe. For more information on actual XSS attacks, check out http://ha.ckers.org/xss.html. Another excellent site is the XSS Database which details each attack and how it works.

PHP代码
  1. <?php  
  2. function RemoveXSS($val) {  
  3.    // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed  
  4.    // this prevents some character re-spacing such as <java\0script>  
  5.    // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs  
  6.    $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/'''$val);  
  7.      
  8.    // straight replacements, the user should never need these since they're normal characters  
  9.    // this prevents like <IMG SRC=@avascript:alert('XSS')>  
  10.    $search = 'abcdefghijklmnopqrstuvwxyz'; 
  11.    $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  
  12.    $search .= '1234567890!@#$%^&*()'; 
  13.    $search .= '~`";:?+/={}[]-_|\'\\'; 
  14.    for ($i = 0; $i < strlen($search); $i++) { 
  15.       // ;? matches the ;, which is optional 
  16.       // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars 
  17.     
  18.       // @ @ search for the hex values 
  19.       $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; 
  20.       // @ @ 0{0,7} matches '0' zero to seven times  
  21.       $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; 
  22.    } 
  23.     
  24.    // now the only remaining whitespace attacks are \t, \n, and \r 
  25.    $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); 
  26.    $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); 
  27.    $ra = array_merge($ra1, $ra2); 
  28.     
  29.    $found = true; // keep replacing as long as the previous round replaced something 
  30.    while ($found == true) { 
  31.       $val_before = $val; 
  32.       for ($i = 0; $i < sizeof($ra); $i++) { 
  33.          $pattern = '/'; 
  34.          for ($j = 0; $j < strlen($ra[$i]); $j++) { 
  35.             if ($j > 0) { 
  36.                $pattern .= '(';  
  37.                $pattern .= '(&#[xX]0{0,8}([9ab]);)'; 
  38.                $pattern .= '|';  
  39.                $pattern .= '|(&#0{0,8}([9|10|13]);)'; 
  40.                $pattern .= ')*'; 
  41.             } 
  42.             $pattern .= $ra[$i][$j]; 
  43.          } 
  44.          $pattern .= '/i';  
  45.          $replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag  
  46.          $val = preg_replace($pattern$replacement$val); // filter out the hex tags  
  47.          if ($val_before == $val) {  
  48.             // no replacements were made, so exit the loop  
  49.             $found = false;  
  50.          }  
  51.       }  
  52.    }  
  53.    return $val;  
  54. }   

经过这样的过滤后,应该被攻击的机会会少上很多吧?试试看呢?

Tags: php, xss, filter, function