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.