Wind__Fantasy

导航

公告

统计

置顶随笔 #

[置顶][原创]在线视频下载(Using Python / Bash / C / Reguar Expressions)

摘要: Windows上下载在线视频不是很难, 可以安装爱酷等对应在线视频(这里是优酷)的官方下载工具, 更通用地, 可以使用硕鼠下载, 这个软件我没用过, 但我需要使用硕鼠官方网站http://www.flvcd.com(支持70多个在线视频网站的解析, 好强大的说)的视频解析作为代理将某个在线视频播放地址解析成对应的下载地址, 我使用Python和正则表达式进行抓取我想要的部分(下载地址以及视频标题)并且下载给定视频地址的视频, 这个脚本如下:#!/usr/bin/env pythonimport sysdef output(s): sys.stderr.write(s + "\n&qu阅读全文

posted @ 2012-01-30 14:00 Wind__Fantasy 阅读(1629) 评论(3) 编辑

[置顶][JavaScript]偶自己的JavaScript扩展库(一点一点完善中...)

摘要: 所有的对内置对象扩展的方法都是以x(stands for 'extend')开头, 非扩展内置对象的方法按英文原意命名, 然后命名空间为wf(stands for wind fantasy)Object.prototype.xattach = function (obj, nooverwrite) { for (var prop in obj) { // if the property exists and disallow the property to be overwritten, just skip if (typeof this[prop] != 'undef阅读全文

posted @ 2011-11-23 16:23 Wind__Fantasy 阅读(37) 评论(0) 编辑

2012年2月21日 #

[短文本]免费版google翻译(PHP)

google翻译api要收费了, 所以想法写了个免费版本的google翻译:

 

<?php


  /**
   * translate [short] text from source language to target language using google translate proxy
   * be careful if google data type or url has been modified
   */
  class GoogleTranslater
  {
    protected $text, $source, $target, $url, $holder;
    const REMOTE_TRANSLATE_URL='http://translate.google.com/translate_a/t?client=t&text=%TEXT%&hl=de&sl=%SL%&tl=%TL%&multires=1&otf=2&ssel=3&tsel=3&sc=1';
    public function __construct($text, $source='en', $target='de')
    {
      $this->source=$source;
      $this->target=$target;
      $this->text=$text;
      $this->holder=array();
      $this->url=str_replace(array('%TEXT%', '%SL%', '%TL%'), array($text, $source, $target), self::REMOTE_TRANSLATE_URL);
    }
    public function getTranslateResult()
    {
      $ch=curl_init($this->url);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
      curl_setopt($ch, CURLOPT_REFERER, 'http://translate.google.com/');
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      $response = curl_exec($ch);
      curl_close($ch);
      $json = json_decode(preg_replace('/,{2,}/', ',', $response), true);
      return ($json && isset($json[0]) && isset($json[0][0]) && isset($json[0][0][0])) ? $json[0][0][0] : null;
    }
  }
  $gt = new GoogleTranslater('你好, 世界!', 'zh', 'en');
  $r = $gt->getTranslateResult();
  echo "$r\n";
?>

 

 输出为: Hello , world !

 替换'你好, 世界!'为其他的中文运行试试看

posted @ 2012-02-21 15:38 Wind__Fantasy 阅读(113) 评论(2) 编辑

2012年1月30日 #

[原创]在线视频下载(Using Python / Bash / C / Reguar Expressions)

摘要: Windows上下载在线视频不是很难, 可以安装爱酷等对应在线视频(这里是优酷)的官方下载工具, 更通用地, 可以使用硕鼠下载, 这个软件我没用过, 但我需要使用硕鼠官方网站http://www.flvcd.com(支持70多个在线视频网站的解析, 好强大的说)的视频解析作为代理将某个在线视频播放地址解析成对应的下载地址, 我使用Python和正则表达式进行抓取我想要的部分(下载地址以及视频标题)并且下载给定视频地址的视频, 这个脚本如下:#!/usr/bin/env pythonimport sysdef output(s): sys.stderr.write(s + "\n&qu阅读全文

posted @ 2012-01-30 14:00 Wind__Fantasy 阅读(1629) 评论(3) 编辑

2011年12月8日 #

mac osx 获取内网ip的方法

(1) ping -c 1 $(hostname) | grep -m 1 -oP '(\d+\.)+\d+' # ping selfhost and catch the first matched ip

 

(2) host $(hostname) | grep -oP '(\d+\.)+\d+' # catch matched ip from selfhost's hostname and ip

posted @ 2011-12-08 10:07 Wind__Fantasy 阅读(25) 评论(0) 编辑

2011年11月23日 #

[JavaScript]偶自己的JavaScript扩展库(一点一点完善中...)

所有的对内置对象扩展的方法都是以x(stands for 'extend')开头, 非扩展内置对象的方法按英文原意命名, 然后命名空间为wf(stands for wind fantasy)

Object.prototype.xattach = function (obj, nooverwrite) {
  for (var prop in obj) {
    // if the property exists and disallow the property to be overwritten, just skip
    if (typeof this[prop] != 'undefined' && nooverwrite) {
      continue;
    }
    this[prop] = obj[prop];
  }
  return this;
}
        
String.xattach({
  xrepeat: function (repeat, times) {
    return new Array(times+1).join(repeat);
  }
});
        
String.prototype.xattach( {
  xrepeat: function (times) {
    return String.xrepeat(this, times);
  }
});
        
Array.xattach({
  'xrange': function (start, stop, step) { // python-like range
    var value, range = [];
    if (arguments.length == 1) {
      stop = start;
      start = 0;
    }
    if (isNaN(stop) || isNaN(start)) {
      return null;
    }
    if (isNaN(step) || step == 0)
      step = start < stop ? 1 : -1;
    if (step > 0) {
      for (value = start; value < stop; value += step)
        range.push(value);
    } else {
      for (value = start; value > stop; value += step)
        range.push(value);
    }
    return range;
  }
});
        
Array.prototype.xattach({
  //        toString: function () { // better toString
  //          return ' [' + this.join(',') + '] ';
  //        },
  xcopy: function () { // shallow copy
    return this.slice();
  },
  // [1,2,3,4,5].xgroup(2) => [ [1,2], [2,3], [3,4], [4,5] ]
  xgroup: function (count) { // group all subsequences of which the length is count from this
    var i, targetlen = this.length - count + 1, target = [];
    for (i = 0; i < targetlen; ++i)
      target[i] = this.slice(i, i+count);
    return target;
  },
  // ['a', 'b', 'c']; xmap(null, parseInt, true, 16) => [10, 11, 12]
  // if you don't want to change array itsself and wanna get the return value, you
  // can do like this: arr.xcopy().xmap(null, parseInt, true, 16) // just change its (shallow) copy
  xmap: function (thisobj, func, changeself, extraargs) { // map this with thisobj.fuc
    var i = 0, len = this.length;
    if (! (extraargs instanceof Array)) {
      extraargs = Array.prototype.slice.call(arguments, 3);
    }
    if (changeself) {
      for (i=0; i < len; ++i) {
        this[i] = func.apply(thisobj, [ this[i] ].concat(extraargs));
      }
    } else {
      for (i=0; i < len; ++i) {
        func.apply(thisobj, [ this[i] ].concat(extraargs));
      }
    }
    return this;
  }
});

posted @ 2011-11-23 16:23 Wind__Fantasy 阅读(37) 评论(0) 编辑

仅列出标题