Skip to content

Instantly share code, notes, and snippets.

@sivagao
sivagao / minimal_pubsub.js
Created April 2, 2013 10:02
minimal pubsub js
var pubsub = function(l, u, r, i) { // cool! 闭包并且初始化vars
return function(n, f) {
r = l[n] = l[n] || [], i = -1;
if (f && f.call) r.push(f);
else while (r[++i]) r[i].apply(u, arguments);
}
}({});
// subscribe to event
pubsub("eat_cookie", function() {
cfhdojbkjhnklbpkdaibdccddilifddb Adblock Plus 10000000
gighmmpiobklfepjocnamgkkbiglidom AdBlock 10000000
efaidnbmnnnibpcajpcglclefindmkaj Adobe Acrobat 10000000
gomekmidlodglbbmalcneegieacbdmki Avast Online Security 10000000
eofcbnmajmjmplflapaojjnihcjkigck Avast SafePrice 10000000
chfdnecihphmhljaaejmgoiahnihplgn AVG Web TuneUp 10000000
flliilndjeohchalpbbcdekjklbdgfkk Avira Browser Safety 10000000
gpdjojdkbbmdfjfahjcgigfpmkopogic Pin It Button 10000000
lifbcibllhkdhoafpjfnlhfpfgnpldfl Skype 10000000
mallpejgeafdahhflmliiahjdpgbegpk FromDocToPDF 9298905
@sivagao
sivagao / JS:doubanEnhance.js
Created May 22, 2013 16:57
JS:doubanEnhance.js - 增强网站的插件典范!!!
// ==UserScript==
// @name 豆藤 Bean vine
// @namespace http://userscripts.org/scripts/show/49911
// @description 为豆瓣(www.douban.com)添加各种人性化的功能。
// @require http://autoupdate.sinaapp.com/autoupdatehelper.js
// @include http*
// @version 2012.12.19
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
@sivagao
sivagao / html5_websql_stickynotes.html
Created April 6, 2013 14:49
HTML5: WebSQL - stickynotes
<!doctype html>
<html manifest="StickyNotes.manifest">
<head>
<title>WebKit HTML 5 SQL Storage Notes Demo</title>
<style>
body {
font-family: 'Lucida Grande', 'Helvetica', sans-serif;
}
@sivagao
sivagao / Ruby: using Timeout, TCPServer, socket, net,ssh, pcaplet(packet analysis).rb
Created November 7, 2012 09:49
using Timeout, TCPServer, socket, net,ssh, pcaplet(packet analysis)/http#practical ruby for system administrator
require "socket"
socket = TCPSocket.open("www.theonion.com", "80")
TCPSocket.open("www.theonion.com", 80) do |socket|
socket.puts "GET / HTTP/1.0\n\n"
puts socket.read
end
@sivagao
sivagao / one_line_html.html
Created March 2, 2013 15:21
one line with data:text/html,<html></html>
data:text/html,<html lang="en"><head><style> html,body { height: 100% } #note { width: 100%; height: 100% } </style> <script> var note, html, timeout; window.addEventListener('load', function() { note = document.getElementById('note'); html = document.getElementsByTagName('html')[0]; html.addEventListener('keyup', function(ev) { if (timeout) clearTimeout(timeout); timeout = setTimeout(saveNote, 100); }); restoreNote(); note.focus(); }); function saveNote() { localStorage.note = note.innerText; timeout = null; } function restoreNote() { note.innerText = localStorage.note || ''; } </script> </head><body><h1>Notepad (type below, notes persist)</h1> <p id="note" contenteditable=""></p> </body></html>
@sivagao
sivagao / sinatra.README.rdoc
Created November 12, 2012 00:54
sinatra.readme.en

Sinatra

Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort:

# myapp.rb
require 'sinatra'

get '/' do
  'Hello world!'
@sivagao
sivagao / Ruby: RR , flexmock testing doubles.rb
Created November 9, 2012 20:59
test doubles: mock, stub, proxy, spy, and so on . Ruby RR , flexmock
# RR
# RR (Double Ruby) is a test double framework that features a rich selection of double techniques and a terse syntax.
#
#
# one of the goal of RR is to make doubles more scannable.
# accomplished by making the double declartion look as much as the actual method invocation as possible
flexmock(User).should_receive(:find).with('42').and_return(jane) # Flexmock
User.should_receive(:find).with('42').and_return(jane) # Rspec
User.expects(:find).with('42').returns {jane} # Mocha
User.should_receive(:find).with('42') {jane} # Rspec using return value blocks
@sivagao
sivagao / readme.md
Created January 28, 2019 02:23
JavaScript Testing Overview with pingcap adaptor

An Overview of JavaScript Testing

通常来说,JS 开发者不习惯网站开发测试,JS 测试一般会很局限,难以实施,运行慢和写起来费时。

Test Types

测试类型可以分为很多种,具体可以参考[reference]。但最主要有如下三种:

  • 单元测试 Unit Tests- Testing of individual functions or classes by supplying input and making sure the output is as expected.
  • 集成测试 Integration Tests- Testing processes or components to behave as expected, including the side effects.
@sivagao
sivagao / rxjs_operators_by_example.md
Created January 23, 2019 10:13 — forked from btroncone/rxjs_operators_by_example.md
RxJS 5 Operators By Example