Skip to content

Instantly share code, notes, and snippets.

View hebuliang's full-sized avatar

He Liang hebuliang

View GitHub Profile
@hebuliang
hebuliang / client.js
Created March 11, 2012 13:20
Simple handshake demo for [RFC 6455]
(function() {
// 注:Firefox 11.0已经去掉了WebSocket对象特有前缀
var ws = new WebSocket('ws://localhost:8888');
ws.onopen = function(e){
// ws.send('Client message!!');
}
ws.onmessage = function(e) {
// TODO
};
@hebuliang
hebuliang / frame.js
Created March 16, 2012 08:36
WebSocket server data frame anlysis for [RFC6455]
/**
* 服务器端解析客户端数据
* WebSocket Frame格式
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-------+-+-------------+-------------------------------+
|F|R|R|R| opcode|M| Payload len | Extended payload length |
|I|S|S|S| (4) |A| (7) | (16/64) |
|N|V|V|V| |S| | (if payload len==126/127) |
| |1|2|3| |K| | |
@hebuliang
hebuliang / ws.js
Created March 22, 2012 13:36
Extremely simple WebSocket Server dosen't contain a fault-tolerant
/**
* WebSocket服务器测试程序
* Surpport [RFC 6455] only
*/
var util = require("util")
,net = require("net")
,http = require("http")
,crypto = require('crypto')
,buffer = require('buffer')
,PORT = 8888
@hebuliang
hebuliang / count
Created May 16, 2012 14:10
jSQL count function
count: function(key) {
var count = 0, scope = key.split('.');
if(key === '*')
this._buffer = this._currentDB;
for(var key in this._currentDB) {
if (this._currentDB.hasOwnProperty(key)) {
var tmp = this._currentDB[key];
for(var i=0,j=0; i<(j=scope.length); i++) {
tmp = tmp[scope[i]];
if(!!tmp && i == j - 1) count++;
@hebuliang
hebuliang / post_spec.rb
Created August 5, 2016 04:11
home work of feature test
require 'rails_helper'
RSpec.feature 'post feature', type: :feature do
scenario 'create new post' do
visit '/posts'
expect(find('.left > a')).to have_content('New Post')
click_link('New Post')
expect(page).to have_selector('.actions > input')
fill_in('post_title', with: 'New Post 1')
fill_in('post_content', with: 'Content of New Post 1')
@hebuliang
hebuliang / render-react-with-rxjs.md
Created December 1, 2016 06:41 — forked from zxbodya/render-react-with-rxjs.md
React with RxJS, reactive way :)

Observable React elements with RxJS

Note: if you want to skip history behind this, and just looking for final result see: rx-react-container

When I just started using RxJS with React, I was subscribing to observables in componentDidMount and disposing subscriptions at componentWillUnmount.

But, soon I realised that it is not fun to do all that subscriptions(that are just updating property in component state) manually, and written mixin for this...

Later I have rewritten it as "high order component" and added possibility to pass also obsarvers that will receive events from component.