JavaScript OO

ONE script to understand JavaScript OO :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function MyClass () { // constructor function
var privateVariable = "foo"; // Private variable

this.publicVariable = "bar"; // Public variable

this.privilegedMethod = function () { // Public Method
alert(privateVariable);
};
}

// Instance method will be available to all instance but only load once in memory
MyClass.prototype.publicMethod = function () {
alert(this.publicVariable);
};

// Static variable shared by all instance
MyClass.staticProperty = "baz";

//...
var myInstance = new MyClass();

Clipped from StackOverflow: http://stackoverflow.com/a/1535687/1904043

fonts.rankun.org

搭建一个在国内外都可以访问的 Google Fonts 代理

Google fonts is blocked in China.

– by Google Fonts Unstable in China – Here is How to Fix It

Yah, we all know that. But the general solution for this is awkward to me, Because after I switched the fonts location to http://fonts.useso.com, I can open my blog very quickly inside China, where the useso(360™) located. When I was trying to access it from the outside of China, both Japanese and West American are slow, over 5 seconds to download a 800 Bytes file, That’s unbearable.

Then I tried to use Qiniu as a CDN to cache fonts.googleapi.com, then I realized it’s blocked anyway. Afterwards, I use the CDN to cache fonts.useso.com, still doesn’t work at all, it persist showing me this:

1
2
3
{
error: "get from image source failed: E400"
}

Read More

Bitcoin playground

使用 Blockchain 的服务进行比特币交易

Use blockchain bitcoin service to transfer bitcoins

Wallet api

1
2
3
4
5
6
7
8
https://blockchain.info/merchant/$guid/payment
?password=$main_password
&second_password=$second_password
&to=$address
&amount=$amount
&from=$from
&fee=$fee
&note=$note

Request tips:

The My Wallet API provides a simple interface Merchants can use interact with their wallet. Blockchain.info will decrypt the wallet on our server manipulate it as necessary and re-save. HTTP GET and POST are supported. However, if a POST request is sent without “Content-Type: application/x-www-form-urlencoded” header, some endpoints may not work correctly.

Read More

Colnect Finding Marketing Guy In China

大!!!家,Colnect.com决定要来国内开展业务了。

##colnect.com

网站概况:colnect.com是一家面向收藏家的网站,colnect即collectors connection / connect collectors,意在连接收藏家,做收藏家的好帮手。网站现在已经有来自221个国家的7万8千余名注册收藏家。

网站功能:收藏品目录运作方式与百度百科类似,每一类收藏品都包含很多具体的收藏品。可以浏览及分享收藏品,注册用户可以标注为自己拥有这个收藏品、有而且可供交换、希望拥有等。用户也可以发起请求添加colnect还没有收录的收藏品,如果你有很多收藏品,将它们全部记录在colnect网站上将会给你的收藏品管理浏览及交易带来极大的方便。

招聘!!:网站推广人员,专门寻找国内的潜在用户。

Read More

骑到天边

To do

  • Create the Article and post it on Gitcafe & Github.
  • Setup Qiniu CDN.
  • Write the Article.
  • Find a way to orgnize Images.
  • Find a way to orgnize Videos.
  • Convert All Videos with YouTube.
  • Upload all Images and Videos to Qiniu CDN.
  • Write a script to mentain the image & video links location (refer to Qiniu CDN).

后续更新

  • 2014-09-18 这辆自行车,掉了……锁在在广汉市东西路德克士门口,买东西20分钟,中途我出来看了一次,第二次出来看已经没了,我就那么盯着空荡荡的电线杆,想着或许能再见或许不能再见。后来报了警,做了笔录。心里想着ta就这么没了,我还想哪天空了给ta洗洗,挣了钱就给ta把有点问题的后轮换掉。没想到ta走的比我还快,更让我痛心的是,ta可能会就这样被放到某个旧货市场,以另一个侮辱ta的价格被卖出去,这肯定是ta不愿意的。

我们到了

终于,在经历了24天骑行之后,我们到达了拉萨。布达拉宫,这座传说中的城堡现在就在我们的眼前。

骑行的每一天都很精彩,经常会遇到一些让自己深思的事儿,世界观没有太多的改变,更多地得到了加强。

Read More

Using FFmpeg to do some simple video process.

Tip:

zsh doesn’t support letters like ‘[‘, ‘]’ etc. so we need to add a Back Slash(\)

rake new_post\[“kicking the ffmpeg”\]

###Because

FFmpeg can’t concatenate .mp4 videos directly, but .ts is ok.

###So

We need to convert all .mp4 files to .ts, then concatenate them together.

####Convert

1
2
3
ffmpeg -i 1.mp4 -c:v copy -c:a copy -vbsf h264_mp4toannexb 1.ts
ffmpeg -i 2.mp4 -c:v copy -c:a copy -vbsf h264_mp4toannexb 2.ts
...
  1. -c:a copy to tell FFmpeg to copy the audio stream, -c:v copy has the same mean.
  2. -vbsf h264_mp4toannexb a encoder use to convert videos to .ts.
  3. -i input file

####Concatenate

1
ffmpeg -i "concat:1.ts|2.ts|3.ts|4.ts" -c:v copy -c:a copy -absf aac_adtstoasc output.mp4

###To simplify this, we need a script as a little program.

1
#Not implement yet

Rocking Rasperry Pi

##Keep in mind

  • Use sudo nmap -sP -T4 10.0.30.1-254 to detect connected devices.
  • Then use sudo nmap -v -A -T4 10.0.30.1 get all opened port and services on this machine.
  • Start a vnc server on raspi. vncserver :1 -geometry 1200x700 -depth 24
  • apt update use goagent proxy. sudo apt-get -o Acquire::http::proxy="http://10.42.0.1:8087/" update
  • Statistic folder size: du -h --max-depth=1

##View the video over mplayer
Install mplayer: sudo apt-get install mplayer

Rasperry Pi: raspivid -t 999999 -o | omxplayer

##Stream video over a network (Official Doc)
Install related tool (both client & raspi): sudo apt-get install mplayer netcat

Some Linux : nc -l -p 5001 | mplayer -fps 31 -cache 1024 -
(Record on the other side: nc -l -p 5001 | ffmpeg -r 31 -i - out.avi)

Rasperry Pi: raspivid -t 999999 -o - | nc 10.42.0.1 5001

##Camera Error

1
2
3
4
5
$ raspistill -o haha.jpg
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

Fixed by: Kernels >= 3.10: w1_gpio destroys i2c bus 0, raspicam doesn’t work anymore

##Connect to Wifi

  1. ifconfig: Enable your wireless device.
  2. iwlist: List the available wireless access points.
  3. iwconfig: Configure your wireless connection.
  4. dhclient: Get your IP address via dhcp.
  5. /etc/network/if-up.d/upstart
1
2
3
iwlist wlan0 scan
sudo iwconfig wlan0 essid rk_mint key s:password123
sudo dhclient wlan0

##Load Camera to /dev/video0 HELP

1
uv4l --driver raspicam --auto-video_nr

##Motion detect HELP

1
LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so motion -c ./motion.conf

Python Learning on

###Knowledge Points

####list

creates lists from iterables.

####else Clauses on Loops (python doc equals if no break else do)

When used with a loop, the else clause has more in common with the else clause of a try statement than it does that of if statements: a try statement’s else clause runs when no exception occurs, and a loop’s else clause runs when no break occurs.

for n in range(2, 10):
  for x in range(2, n):
    if n % x == 0:
      print(n, '=', x, '*', n // x)
      break
  else:
    print(n, '是素数')

####varible scope (view in python doc)

The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced.

####default values in function definition (Default Argument Values)

The default values are evaluated(and evaluated only once) at the point of function definition in the defining scope, so that

i = 5

def f(arg=i):
    print(arg)

i = 6
f()

will print 5.

透明网络

###目录:

  1. youtube下载视频(包括1080p).
  2. 翻墙.
  3. 不翻墙使用Google Search.
  4. 关于本文.
  5. 解释

###youtube下载视频

  1. 翻墙并打开youtube网站,
  2. 找到要看的视频,
  3. 点击浏览器地址栏,并复制该网址,
  4. 准备解析源地址
    1. Chrome下,简单下载720p视频 (推荐)
      1. 打开Ultimate YouTube Downloader的网站:Ultimate YouTube Downloader
      2. 点击下面的Download (New vx.x.x.x)下载这个扩展,
      3. 依次点击Chrome的设置–>扩展程序,再点击开发者模式打开开发者模式,
      4. 把Chrome浏览器窗口化(点击右上角叉叉左边的按钮),再打开文件管理器,在自己电脑的下载目录,找到刚刚下载的Ultimate_YouTube_xxxx.crx,把它拖到这边浏览器的扩展程序这个页面,松手,安装成功。然后就不用管了,以后会自动升级的。
      5. 现在打开Youtube的视频页面,后边多出来个下载下拉框,点击MP4 720p以720p级别的清晰度下载这个视频。
    2. 仅需要下载720p以下的视频
      1. 使用FLVCD的下载器: 打开flvcd downloader,并点击硕鼠Youtube专用下载器下载硕鼠的下载器,接下来就比较简单了,打开软件书如地址点击下载一气呵成(要记得设置http代理噢)——不推荐
    3. 需要下载1080p级别的高清视频(2013-11-25测试可用)
      1. 使用Kej’s FLV Retriever
        1. 打开它们的网站:Kej’s FLV Retriever
        2. 粘贴刚刚复制的网址到输入框中,然后retrieve now!注意要开着代理,一定要全开,使用VPN全局代理,如果是http代理,goAgent类的,要设置代理程序对所有网址都使用代理,不要使用pac自动识别的方式。
        3. 然后麻烦一点,点击下载页面中的下载此档案指向的文件,然后用记事本打开这个文件,复制所有内容,然后粘贴到下面的文本框中,
        4. 然后更麻烦一点,看到下面的Download (MP4(H.264), 1920 x 1080, no audio)了吧,这个视频下载下来是没有声音的,不过下面还是有audio only格式的音频供下载,有视频和音频,自然有办法合并音视频流。
        5. 点击那个Download (MP4(H.264), 1920 x 1080, no audio)下载视频。
        6. 然后再点击Download (M4A, 256 kbit/s audio only)下载音频。
        7. 注意下载的音视频的格式,两个文件是同名的,都叫videoplayback,但下载的时候一前一后,后者嘛肯定是有个(1)字样结尾的。
        8. 下载一个ffmpeg下来,Windows版已经编译好了的下载地址是:Zeranoe FFmpeg builds。注意自己的电脑版本,打开网页之后就找醒目的32-bit Downloads64-bit Downloads32位看左边,64位看右边,点第一个黑块Download FFmpeg git-xxxxxxx xx-bit Static就会开始下载了。
        9. 解压得到一个ffmpeg.exe,复制当前目录的路径,并看看当前目录在什么盘符下,然后打开命令行,切换到该目录(同时按win+r,输入cmd,按回车,输入cd,鼠标右键粘贴刚刚复制的路径,按回车,如果刚刚的ffmpeg.exe没解压到C盘,cd完了是没效果的,再输入刚刚记下来的盘符:,回车),命令行不要关。
        10. 调用ffmpeg.exe来合并视频,把刚刚下载的两个视频啊音频啊都拷贝到ffmpeg.exe下面来,然后在命令行输入ffmpeg -i "第一个文件的名字" -i "第二个文件的名字" -c:v copy video.mp4,然后回车。
        11. 然后就得到视频了。

Read More