bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

Archive for August, 2007

[原] TP-Link拨号/断开程序

Posted by bianbian on 2007-08-27 07:05


本文Tags: ,

万恶的南京电信好贵啊,,,,,我的套餐是一个月360小时,2M带宽,168元/月
路由器不可能一直联网,需要手动拨号。不过每次都连上192.168.1.1也太麻烦了。
于是写了个程序自动拨号、断开。程序启动就会连上路由器拨号,关闭的时候会断开连接。
tp_link.JPG
需要的朋友请下载(仅适用于TP-Link路由器):tp_link.zip

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in Delphi, Technology | No Comments »

[原]iframe跨域访问解决方案

Posted by bianbian on 2007-08-24 03:09


本文Tags: , , ,

跨域访问提示“没有权限”,真是伤脑筋。研究几天以后,终于得到了所有解决方案。

A:www.bianbian.org
B:test.bianbian.org
C:www.other.com
从A跨域访问B、C,并能控制B、C的页面内容

方案(1)目标页面是自己的(即可以改页面输出),从A->B
最简单的,在B页面输出个

  1. <script>document.domain="www.bianbian.net";</script>

骗骗浏览器就行了

方案(2)目标页面是别人的,从A->C
比较头疼,只能用后台语言 2.1)做个proxy,2.2)做个JS输出(类似JSON方式了)

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in JavaScript, Technology | 3 Comments »

[原] 改进的DOS命令输出重定向到文本框(TMemo)内

Posted by bianbian on 2007-08-17 02:44


本文Tags: , , ,

虽然是Delphi的,都是调用的WinAPI,C++也可参考。
原理就是管道(Pipe),自己的程序可以Create管道出来,让CreateProcess的子程序能继承自己程序里的管道,替代子程序的标准输入输出。
这样DOS程序对stdout输出的内容就输出到自己程序建立的管道里来了,也就能对其进行读取操作,从而完成重定向到文本框(实时显示)。

基本上Delphi世界里流行的都是DFW上的那个重定向代码,我进行了改进:
1)原来那个代码只能截取输出结果,但是没有换行的整理,要是直接Add到Memo里会杂乱不堪(因为循环取到的内容有可能含有 \r 或 \n,这时候直接Add就有了两行)。
我加上了换行符的处理,Add行的时候按实际的换行进行处理,这样和DOS窗口输出就一致了。
2)原来那个代码没有和Memo绑定,还得自己写Memo操作部分
我加上了Memo作为参数,这样直接调用就省事了。

使用的时候只要 CmdExecAndView(”命令”, memo) 即可。

下面是改进后的代码,欢迎交流:

  1. procedure CmdExecAndView(FileName: string; memo: TMemo);
  2.   procedure _AddInfo(mmInfo:TMemo; S: string; var line: string);
  3.   var
  4.     i, p: Integer;
  5.   begin
  6.     if mmInfo.Lines.Count > 800 then
  7.       mmInfo.Lines.Clear;
  8.     //去掉 \r
  9.     for i := 0 to Length(S) - 1 do
  10.       if S[i] = #13 then S[i] := ' ';
  11.     line := line + S;
  12.     // \n 断行
  13.     p := Pos(#10, line);
  14.     if p > 0 then
  15.     begin
  16.       // \n 前面的加入一行,后面的留到下次
  17.       mmInfo.Lines.Add(Copy(line, 1, p - 1));
  18.       line := Copy(line, p + 1, Length(line) - p);
  19.     end;
  20.   end;
  21. var
  22.   hReadPipe, hWritePipe: THandle;
  23.   si: STARTUPINFO;
  24.   lsa: SECURITY_ATTRIBUTES;
  25.   pi: PROCESS_INFORMATION;
  26.   cchReadBuffer: DWORD;
  27.   ph: PChar;
  28.   fname: PChar;
  29.   line: string;
  30. begin
  31.   fname := allocmem(1024);
  32.   ph := AllocMem(1024);
  33.   lsa.nLength := sizeof(SECURITY_ATTRIBUTES);
  34.   lsa.lpSecurityDescriptor := nil;
  35.   lsa.bInheritHandle := True;
  36.   if CreatePipe(hReadPipe, hWritePipe, @lsa, 0) = false then
  37.     Exit;
  38.   fillchar(si, sizeof(STARTUPINFO), 0);
  39.   si.cb := sizeof(STARTUPINFO);
  40.   si.dwFlags := (STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);
  41.   si.wShowWindow := SW_HIDE;
  42.   si.hStdOutput := hWritePipe;
  43.   si.hStdError := hWritePipe;
  44.   StrPCopy(fname, FileName);
  45.   if CreateProcess(nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then
  46.   begin
  47.     FreeMem(ph);
  48.     FreeMem(fname);
  49.     Exit;
  50.   end;
  51.   CloseHandle(hWritePipe);
  52.   while (true) do
  53.   begin
  54.     if not PeekNamedPipe(hReadPipe, ph, 1, @cchReadBuffer, nil, nil) then break;
  55.     if cchReadBuffer <> 0 then
  56.     begin
  57.       if ReadFile(hReadPipe, ph^, 512, cchReadBuffer, nil) = false then break;
  58.       ph[cchReadbuffer] := chr(0);
  59.       _AddInfo(memo, ph, line);
  60.     end
  61.     else if (WaitForSingleObject(pi.hProcess, 0) = WAIT_OBJECT_0) then break;
  62.     Application.ProcessMessages;
  63.     Sleep(200);
  64.   end;
  65.   ph[cchReadBuffer] := chr(0);
  66.   _AddInfo(memo, ph, line);
  67.   CloseHandle(hReadPipe);
  68.   CloseHandle(pi.hThread);
  69.   CloseHandle(pi.hProcess);
  70.   FreeMem(ph);
  71.   FreeMem(fname);
  72. end;
标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in Delphi, Technology | 3 Comments »

[晕] 居然还有这种东西:C++ Trigraph

Posted by bianbian on 2007-08-01 03:34


本文Tags:

听说为了照顾某些键盘坏了又换不起的,可以使用这种3字符的串来代替一些特殊字符,preprocess的时候会替换掉:

#: ??=
\: ??/
^: ??’
[: ??(
]: ??)
{: ??<
}: ??>
|: ??!
~: ??-

于是程序就这样了:

  1. //: S03:trigraph.cpp
  2. ??=include <iostream>
  3.  
  4. int main(int argc, char* argv??(??)) ??<
  5.     using namespace std;
  6.     unsigned int n;
  7.     if (argc != 2 ??!??! (n = atoi(argv??(1??))) <= 0)
  8.         return 1;
  9.     cout << ??-(n ??' 0xf0f0) << '??/n';
  10.     return 0;
  11. ??>

我就奇怪了,键盘换不起,眼睛换换就那么便宜吗?

标签:

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Technology | 2 Comments »

[原] 淘宝(taobao.com)卖家自动好评工具

Posted by bianbian on 2007-08-01 02:23


本文Tags: , , ,

哈哈,每天点好评太郁闷了,这下爽了。写了一晚上,有什么问题请留言阿。
==================
taobao卖家自动好评工具 v1.1
==================
解压后运行Setup.exe来安装和卸载(第一次运行安装,下一次卸载,再下一次安装。。。。)

安装和卸载都要重新打开浏览器(IE和IE核心的)才有效。

使用的时候:右键点击“评价”链接,选择“taobao卖家自动好评”
淘宝卖家自动好评

因浏览器的关系,会弹出一个对话框,等待自动评价完成(否则浏览器立刻返回就不灵了)

评价的内容修改请用记事本或写字板打开“Haoping.html”第36行参照说明修改

有什么问题,请到我的blog留言:http://bianbian.org

最后做个广告:

欢迎光临必胜客优惠券打折卡专卖:http://shop34553802.taobao.com

保留作者信息下随意复制本程序

bianbian
http://bianbian.org
http://shop34553802.taobao.com

07.8.1

下载:淘宝卖家自动好评工具v1.1 (43K)

原理就是JS控制页面元素啦,还是比较有意思的。
源码:

  1. //***************************************************************
  2. //   Function   : 淘宝卖家自动好评
  3. //   File name  : Haoping.html
  4. //   Author     : bianbian (bianbian.org#gmail.com)
  5. //   Blog       : http://bianbian.org
  6. //   Shop       : http://shop34553802.taobao.com
  7. //   Copyright  : 保留作者信息下随意复制
  8. //   Version    : 1.0  created,      bianbian @ 07-7-31 18:46
  9. //                1.1  解决跨域问题, bianbian @ 07-8-1 1:43
  10. //***************************************************************
  11.  
  12. /*
  13. 在下一行修改你的好评内容,注意如果多行要用"\n"隔开,如:
  14.  
  15. content = "欢迎再次\n光临\n必胜客优惠券打折卡\n专卖\n shop34553802.taobao.com";
  16.  
  17. 也可以写成这样:
  18.  
  19. content = "欢迎再次\n" +
  20. "光临\n" +
  21. "必胜客优惠券打折卡\n" +
  22. "专卖\n" +
  23. " shop34553802.taobao.com";
  24.  
  25. 也可以这样:
  26.  
  27. content = "欢迎再次\n\
  28. 光临\n\
  29. 必胜客优惠券打折卡\n\
  30. 专卖\n\
  31. shop34553802.taobao.com\
  32. ";
  33. */
  34. content = "欢迎再次光临必胜客优惠券打折卡专卖~ shop34553802.taobao.com";
  35.  
  36.  
  37. //
  38. // 下面不需要修改 ***********************************************
  39. //
  40. try
  41. {
  42.     haoping();
  43. }
  44. catch(e)
  45. {
  46.     alert("出错了噢~ 请和 yuelinniao 联系");
  47. }
  48.  
  49. function haoping()
  50. {
  51.     var d = external.menuArguments.document;
  52.     var e = external.menuArguments.event;
  53.     var a = d.elementFromPoint(e.clientX, e.clientY);
  54.     var p = a.parentElement;
  55.     var done = 0;
  56.    
  57.     if (a.innerText != "评价")
  58.     {
  59.         alert("你点错了吧~~~");
  60.         return;
  61.     }
  62.     a.innerText = "好评中..";
  63.     var fr = d.createElement("IFRAME");
  64.     fr.width = 1;
  65.     fr.height = 1;
  66.     //bianbian: 这里涉及iframe的跨域问题,暂时先改成同个域解决
  67.     fr.src = a.href.replace("http:\/\/my\.taobao\.com", "");
  68.     fr.onreadystatechange = function ()
  69.     {
  70.         if (fr.readyState == "complete")
  71.         {
  72.             if (done == 0) //submit form
  73.             {
  74.                 if (submitfrm(fr.contentWindow.document.forms))
  75.                 {
  76.                     done = 1;
  77.                     return;
  78.                 }
  79.                 else //failed, roll back
  80.                 {
  81.                     p.removeChild(fr);
  82.                     a.innerText = "评价";
  83.                 }
  84.             }
  85.             else if (done == 1) //submited, clear
  86.             {
  87.                 p.removeChild(fr);
  88.                 p.removeChild(a);
  89.                 var span = d.createElement("SPAN");
  90.                 span.innerText = "好评OK!";
  91.                 p.appendChild(span);               
  92.             }
  93.             done = 99;
  94.         }
  95.     };
  96.     p.appendChild(fr);
  97.     //bianbian: 这里必须弹出个对话框,否则IE会清空资源直接返回,onreadystatechange就失效了
  98.     alert('好评进行中,完成才能点击"确定"关闭本对话框噢~');
  99.     if (!done)
  100.     {
  101.         p.removeChild(fr);
  102.         a.innerText = "评价";
  103.         alert("提早关闭对话框,无法取得结果,请重试");
  104.     }
  105. }
  106.  
  107. function submitfrm(fms)
  108. {
  109.     for (var i = 0; i < fms.length; i++)
  110.     {
  111.         var f = fms[i];
  112.         if (f.name == "addfeedback")
  113.         {
  114.             f["_fmmy.r._0.r"][0].checked = true;
  115.             f["_fmmy.r._0.c"][0].checked = true;
  116.             f["_fmmy.r._0.t"][0].checked = true;
  117.             f["_fmmy.r._0.f"].value = content;
  118.             f.submit();
  119.             return true;
  120.         }
  121.     }
  122.     return false;
  123. }
标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in JavaScript, Technology | 2 Comments »