damien.h

twtplus updated for Ubiquity 0.5+

I’ve updated the “twtplus” command for Ubiquity 0.5+. Since Github Gist sucks right now, (it’s very slow and cuts off the last lines of the code randomly without any prompt) I’m publishing the script here on my blog. Note that this is only compatible with Ubiq 0.5+ now.
twtplus.ubiq.js

Running Greasemonkey scripts on Ubiquity

Mozilla Ubiquity is not only a wonderful command engine and launcher. It can also be used to do stuff what Greasemonkey is good at, manipulating page DOM dynamically, by utilizing the “pageLoad_” function hook. To demonstrate this case I’ve quickly migrated the recently popular Twitter search on Google monkey script onto Ubiquity. You can get the Ubiq version of Twitter+Google search from here.

I retained the original DOM building code, but replaced the Ajax call with a JQuery one along with a couple hacks explained below to get it working from Ubiquity.

First, while Greasemonkey has built-in mechanism for filtering page URLs for selective script invocation, you have to do that on your own with Ubiquity. Look at the first few lines in the Ubiq command for the regex job to filter out Google search addresses.

    var href = doc.location.href;
    var q = (/^https?:\/\/(?:www\.)?google\..*\/.*[&?]q=([^&]*)(?:&|$)/(href)||0)[1];

Secondly, before publishing the script, you have to put such a line of comment in the script in order for Ubiquity to consider it an installable command and trigger the install bar at the top of the page. (Kudos to satyr for pointing out this hack)

//function cmd_

In similar ways, most of the Greasemonkey scripts can be migrated to Ubiquity.

用Launchy提高你的生活品质:直接搜索你想要的任何东西

几天前Launchy 2.0发布了。2.0出现了哪些新功能呢?其实并没有什么惊天动地的新功能,Launchy已经很好的达到了简约而强大的目的了,如果越变越复杂的话其实会违背其本意。2.0主要是改善了界面和易用性,可扩展性。

用了几天Launchy 2.0以后,有一个实实在在非常有用的用法分享给大家:直接从Launchy向常用的网站提交搜索。用法是这样的:

  1. 从Launchy右上角的按钮进入Optionsimage2.png
  2. 在Plugins里选择Weby插件image3.png
  3. 在Weby配置里添加你最常用的网站搜索URL和查询格式。比如淘宝,URL是:http://search1.taobao.com/browse/search_auction.htm,Query是:?q=%s
    其中%s是使用Launchy搜索淘宝的时候输入的字串。
    image4.png
  4. 设好了!使用起来只要Alt+Space召唤出Launchy,然后打taobao+TAB+搜索字串,直接就能打开淘宝搜索结果页面了。再也不用为了搜一点东西摸上网站填表提交了。爽吧!
    image5.png

和大家分享一下我在默认搜索之外添加的常用搜索:

taobao http://search1.taobao.com/browse/search_auction.htm ?q=%s
shooter http://shooter.cn/sub/ ?searchword=%s
nti http://www.newtorrents.info/search/ %s
mininova http://www.mininova.org/search/ ?search=%s
gmail http://mail.google.com/mail/#search/ %s
ciba http://dict.iciba.com/search ?s=%s
flickr http://www.flickr.com/search/ ?q=%s

要添加你自己常用的搜索,只要照常在网页上搜索的时候留意一下搜索结果的URL,或者看看form的代码,就知道怎么设置Launchy了。

接下来,把Firefox search bar里面的search engine和google toolbar上的custom search全都搬到Launchy上来吧!

LinkStation改装攻略备忘 补充

今天拿了台新换的linkstation回来,很快又改会原来的状态了。上次写的备忘有些需要补充的地方。

  1. 这次试验了ls2直接连电脑后,在电脑和ls2的c网段不同的情况下刷机。结果是firmware刷新失败!不过不用怕,firmware刷新失败后ls2会进入工程模式(Engineer Mode, EM)。这时候ip会回到默认的192.168.11.150,firmware刷新工具仍旧能搜索到ls2。把电脑设置到和ls2相同c网段,重新刷一次就行了。
  2. 建议在第一次e2fsck检查完Debian分区,重启进系统之后,执行tune2fs -i 0 -c 0 /dev/hda1,禁止系统启动时自动检查硬盘,从而避免出现检测超时无法开机的麻烦情况。
  3. 快速改机档的默认ip直接修改/mnt/hda/etc/network/interfaces,这样就不用重启进入Debian再接上电脑改了

LinkStation改装攻略备忘 svn + 动态域名

有2周多没有更新blog了吧,最近在折腾不少事情,升级了台式机,hack了新买的linkstation HD-H120LAN(以下简称ls2),想打造一个高效的soho环境。工欲善其事必先利其器嘛,好的环境和工具是非常必要的。

Linkstation的改装基本按照计划,初步完工以后这个白色的小家伙跑着Debian连续工作了两个礼拜,120G硬盘塞满了90%,这周三突然挂了,为了不破保不敢拆机,于是今天去送修,基本要换个新的了。虽然除了意外,但是linkstation的改装真的是非常值得做的,改装以后非常超值。为了拿到新机以后再改一次,还是把本次改装经过记录下来备忘吧。

国外玩家对linkstation的改装已经很有造诣了,改装社区2年多前就很热了,所以其实现在对linkstation的改装资源已经很成熟了。我的改装过程基本参照这里这里的两篇文章,用了文章里的Debian快速改装包,装完Debian以后常用的工具都已经预装好了,包括torrentflux, mldonkey, samba, lamp, phpmysqladmin。具体过程参照文章就行了,但是有几点要注意。

  1. 关于第三方改装firmware的说明两篇文章都没有交代清楚,刚接触linkstation改装的同学可能会有点晕。linkstation改装的资料在http://www.nas-central.org都有完整说明。最常用的第三方firmware是openlinkfreelink,两者的区别是openlink只是在原厂firmware基础上打开了telnet,其他原厂功能不变,而freelink是直接把原厂linux替换成了Debian。其实也可以直接按照nascentral上面的攻略来改,但上面两篇文章里改法的好处是用了openlink以后在hda3上装Debian,和原厂linux互不影响,可以随时切换,所以是个合理的选择。
  2. 把ls2直接连到电脑以后,电脑不必修改ip到192.168.11网段firmware刷新工具也能搜到ls2。但是我刷的时候为了保险还是把电脑改到11网段了。也许不用改网段也能刷。
  3. 刷完openlink改装版firmware以后,ls2预设的静态ip就是192.168.11.150。因为我用的linksys wireless-b路由只允许192.168.1网段,改完以后不能直接接上路由,不然ls2是拿不到ip的。必须还是连在电脑上的时候把静态ip改掉。由于openlink只是相当于在原厂firmware基础上把原厂linux的telnet打开,所以刷完以后ls2的使用和原来的一摸一样。可以通过http访问192.168.11.150进原厂管理界面直接改掉ip到192.168.1网段,再接到路由上面就行了。
  4. 以下这步非常重要!上面两篇文章里都没有突出这一步的重要性!我的ls2就是因为reboot之前忘了做这一步出问题的!
    强烈建议在每次reboot进debian之前,执行下面操作检查硬盘,防止重启以后因为硬盘检查超时导致无法进入系统的问题!

    umount /dev/hda3
    e2fsck /dev/hda3
  5. 装完Debian以后第一次启动默认静态ip还是192.168.11.150,所以我需要把ls2再接到电脑上改静态ip到192.168.1网段。
  6. 推荐使用下面的Debian源,不推荐第二篇文章里的netselect-apt,至少在我的情况下netselect-apt自动找的源很慢,还会造成deb包的混乱,最后还得用apt-get -f install来整理。
    deb http://mirror.pacific.net.au/debian/ etch main contrib
    deb-src http://mirror.pacific.net.au/debian/ etch main contrib
    deb http://security.debian.org/ testing/updates main
  7. Debian基本都搞舒服了以后就可以根据自己需要装更多软件了。我装了subversion,把ls2用作home lan上的svn server,用下来速度也很不错,推荐一下。apt-get install subversion就行了。顺便说一下我感觉ls2上用svnserve就行了,没必要用apache配webdav,毕竟不是pc还是要节约一下计算资源。
  8. 动态域名问题。之前是打算装花生壳linux版的,后来才发现在ls2的Debian上运行不了,而且没有提供源码,所以就没戏了。后来用的是3322.org,使用非常简单,不需要客户端,只要用lynx定时ping一下3322的web service url就行了。ls2的Debian默认没有lynx,需要apt-get install lynx一下。把下面的命令存为3322org.sh
    lynx -mime_header -auth=user:pass "http://www.3322.org/dyndns/update?system=dyndns&hostname=myhost.3322.org"

    然后chmod +x 3322org.sh,再写个cron job定时执行这条命令:

    crontab -e

    加上这条cron job,每隔5分钟执行一下3322org.sh并把输出保存到3322.org

    */5 * * * * /home/user/3322org.sh >>/home/user/3322.log

    为了防止log文件无限暴涨,可以再加上这条cron job,每天0点删除log

    0 0 * * * rm /home/user/3322org.log

    完了以后别忘了在路由上设好端口映射,之后就可以用动态域名访问ls2上的所有服务了!

搞定!我的完美ls2 server就这样基本完成了!两个星期来已经用torrentflux消耗了无数带宽,还动不动很bt的用手机访问tf。。。等机器拿回来再搞一遍吧。。。

Downloading YouTube Videos with a Groovy one-liner, and convert it to mpeg4

Today I used LiveHTTPHeaders to take a closer look at how the youtube video streams are directed to the browser. And I found that my previous attempt actually has some redundency in it. To get the flv video stream, simply request the URL:

http://cache.googlevideo.com/get_video?video_id=${vid}

where vid is simply the v string in the original URL. e.g. http://www.youtube.com/watch?v=5C0I7Ef4gQI

So the simplified version is one line of code even shorter now.

def vid = (args[0] =~ (/(? new URL("http://cache.googlevideo.com/get_video?video_id=${vid}").openStream().eachByte{it -> os.write(it)}}

And now here’s a bonus. Grab ffmpeg and put the ffmpeg executable to your system path. Then add the following line to the Groovy script above, and the downloaded flv file will be converted to an mpeg4 format mpg file immediately. You can also play with many ffmpeg parameters to fine tune your convertion.

For Windows

Runtime.getRuntime().exec(['cmd', '/c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

For Linux

Runtime.getRuntime().exec(['sh', '-c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

用Launchy发消息到饭否

Launchy真是个用了舍不得放下的小东西,可以双手不离键盘的打开电脑上几乎任何东西。而且,hack一番的话你还可以让Launchy干更多更有趣的事情。

image

比如,今天尝试成功了用Launchy发消息到

Downloading YouTube Videos with a Groovy one-liner, kind of

Inspired by Downloading YouTube videos with a Perl one-liner, I’ve put together a piece of code to do the same thing with Groovy. Not as succinct as Perl. But figure out how much noise there will be in plain Java.

HttpURLConnection.setFollowRedirects(false)
def vid = (args[0] =~ (/(? new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Let’s take a closer look at the code. To capture the redirect location, we must temporarily disallow HttpURLConnection to follow redirects.

HttpURLConnection.setFollowRedirects(false)

Then we extract the v id from the original YouTube URL and compose the URI for the embedded player. Open a connection to the video URI and extract the redirect location from the HTTP header. The input parameter arg[0] should be something like http://www.youtube.com/watch?v=5C0I7Ef4gQI

def vid = (args[0] =~ (/(?<=v=).*$/)).getAt(0)
def uri = ((HttpURLConnection)new URL("http://www.youtube.com/v/$vid").openConnection()).getHeaderField('Location')

Now we must enable http redirects again, otherwise the last line of code won’t work.

HttpURLConnection.setFollowRedirects(true)

Finally, go ahead to compose the video data download URI, open a connection and download the data stream.

new File("${vid}.flv").withOutputStream{os -> new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Save the script to a groovy file like “YoutubeSaver.groovy”. Run the script from command line and give the video URL as the parameter. For example,

groovy youtubesaver http://www.youtube.com/watch?v=5C0I7Ef4gQI

Browse Happy logo

My tweets

2016年五月
« 八    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

分类目录

Articles

Fancy Stats