一個架構在Express之上的nodejs web framework. 用ES6 generator的寫法來寫middleware並加進request flow裡面. 官網有example描述如何在不改動原本的程式碼之下log每一個request process time及增加response header
主講者用javascript來實作p2p protocol並且還自己寫了幾種應用
1. torrent-stream p2p stream data
2. peerflix stream data to VLC
3. torrent-mount mount a virtual file using p2p.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Put your elements inside div.modal
123456
<divid="samplemodal"class="modal-contain"><divclass="modal"><ahref="#">X</a><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></div></div>
I changed the my work frontend module build optimize flow few day ago.
The original build flow is use wro4j plugin and my buildhelper. The cons is that there’re many trivial steps when adding a new page.
I decide to update it with new way. I study the YEOMAN build flow and apply it in my module. The result is good.
YEOMAN uses nodejs and Grunt to do optimize.
But the company module system is using Maven. The first step is to find a maven plugin to run grunt. I choose grunt-maven-plugin and it’s easy to integrate.
Emberjs official document doesn’t describe how to invoke route method/event from controller. Why we need this?
Some methods(like render,controllerFor) only exist in Route scope.
The CSS property pointer-events could control mouse/touch event fired or not. The default value is auto and you can set none to disable event firing. For example:
You have a Sign-in button.
I read some articles about Emberjs Dependency Injection(DI) and try to upgrade my old project food_ntpc
to use DI. The pros of DI is to reduce gobal object and make code clean, testing easily.
There are few changes.
before
I create a CategoryManager and put in FoodNtpc App.
Only the Ember.Object class can be registered. I change class CategoryManager to CategoryManager = Ember.Object.extend.
Then create an initializer to register the CategoryManager in foodntpc:categoryManager naming. Set singleton to true because i want only one CategoryManager in system.
Next, create another initializer to inject those dependency. We can use after or before to adjust initializer sequence.
In application.js line 6 means foodntpc:categoryManager is injected to IndexRoute and use CategoryManager reference.
In line 7 means inject into all controller.
There’s the old post about how to create a ruby gem.
This post is focus on how to add testing to gem.
First, add rspec into your gem dependency. I like to use rspec as my testing framework.
Here i also use webmock to mock my http request during spec testing.
Create a rake task to run rspec. I create rspec.rake under {gem_root_folder}/tasks/.
Set the default task to :spec then i can just type rake to run testing.
In the meantime i set --color -f d to output result with color and document format.
rspec.rake
12345678
require'rspec/core/rake_task'desc'Default: run specs.'task:default=>:specRSpec::Core::RakeTask.newdo|task|task.rspec_opts='--color -f d'end
In order to exec our rspec.rake. Import all .rake file under tasks folder to Rakefile.
Now we could start to write testing.
Create {gem_root_folder}/spec/ folder and spec_helper.rb under it.
spec_helper.rb
12345
# require webmock/rspec to use webmock in rspec testing frameworkrequire'webmock/rspec'# mvn_utils is the target class to be testrequire'mvn_utils'
Create mvn_utils_spec.rb under {gem_root_folder}/spec/ and require spec_helper.
We could require all targets in spec_helper.rb and each spec.rb file just require spec_helper.
mvn_utils_spec.rb
1234567891011121314151617181920
require'spec_helper'describeMvnUtilsdolet(:mvn_base){"mvn.example.net/service/local/repositories/"}let(:header_hash){{'Accept'=>'*/*','Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3','User-Agent'=>'Ruby'}}describe'should find the latest version'dolet(:response_xml){"<metadata><groupId>a.b</groupId><artifactId>x.y</artifactId><versioning>"+"<release>1.0.100</release><versions><version>1.0.98</version>"+"<version>1.0.99</version></versions></versioning></metadata>"}it'find_latest_version'dostub_request(:get,"http://#{mvn_base}a/b/x/y/maven-metadata.xml").with(:headers=>header_hash).to_return(:status=>200,:body=>response_xml,:headers=>{})expect(MvnUtils.find_latest_version).toeq('1.0.100')endend
In the above example, i test MvnUtils.find_latest_version and expect the value should be 1.0.100.
This function will inovke http request to mvn server but i use stub request here to prevent real http connection.
With stub request i could control the returned xml data.
varfoo="i am foo";varobj={__proto__:[],// 定義方法getLength(){returnthis.length;},// 動態設定變數/方法名稱['prop_'+(()=>42)()]:"Should be 42",//foo:foo 的縮寫foo};obj.push("1");console.log(obj.getLength());//1console.log(obj.prop_42);//"Should be 42"console.log(obj.foo);//"i am foo"
classPolygon{constructor(height,width){//class constructorthis.name='Polygon';this.height=height;this.width=width;}staticdoIt(){//class methodconsole.log('Do it now');}}classSquareextendsPolygon{constructor(length){super(length,length);//call the parent method with superthis.name='Square';}getarea(){//calculated attribute getterreturnthis.height*this.width;}}lets=newSquare(5);console.log(s.area);//25Square.doIt();//"Do it now"
varmyString=`InJavaScript'\n'isaline-feed.`;// Multiline stringsvarmyString2=`InJavaScriptthisisnotlegal.`;varname="Bob",time="today";varmyString3=`Hello${name},howareyou${time}?`console.log(myString);//"In JavaScript ' ' is a line-feed."console.log(myString2);//"In JavaScript this is not legal."console.log(myString3);//"Hello Bob, how are you today?"functiontag(strings,...values){if(!(strings[0]==='a'&&strings[1]==='b')){return'bad';}return'good';}console.log(tag`a${123}b`);// "good"console.log(tag`c${123}d`);// "bad"
// same as ES5.1console.log("𠮷".length==2);//true// new RegExp behaviour, opt-in ‘u’//console.log("𠮷".match(/./u)[0].length == 2); //在ES6模擬器上無法使用// new formconsole.log("\uD842\uDFB7"=="𠮷");//true//console.log("\u{20BB7}" == "𠮷"); //在ES6模擬器上無法使用// new String opsconsole.log("𠮷".codePointAt(0)==0x20BB7);//true//在ES6模擬器上無法使用// for-of iterates code points//for(var c of "𠮷") {// console.log(c);//}
// Setsvars=newSet();s.add("hello").add("goodbye").add("hello");s.size===2;s.has("hello")===true;// Mapsvarm=newMap();m.set("hello",42);m.set(s,34);m.get(s)==34;// Weak Mapsvarwm=newWeakMap();wm.set(s,{extra:42});wm.size===undefined// Weak Setsvarws=newWeakSet();ws.add({data:42});// Because the added object has no other references, it will not be held in the set
// Proxying a normal objectvartarget={};varhandler={get:function(receiver,name){return`Hello,${name}!`;}};varp=newProxy(target,handler);p.world==='Hello, world!';
12345678910
// Proxying a function objectvartarget=function(){return'I am the target';};varhandler={apply:function(receiver,...args){return'I am the proxy';}};varp=newProxy(target,handler);p()==='I am the proxy';
varpromise=newPromise(function(resolve,reject){// do a thing, possibly async, then…if(/* everything turned out fine */){resolve("Stuff worked!");}else{reject(Error("It broke"));}});promise.then(function(result){console.log(result);// "Stuff worked!"},function(err){console.log(err);// Error: "It broke"});
Number.EPSILONNumber.isInteger(Infinity)// falseNumber.isNaN("NaN")// falseMath.acosh(3)// 1.762747174039086Math.hypot(3,4)// 5Math.imul(Math.pow(2,32)-1,Math.pow(2,32)-2)// 2"abcde".contains("cd")// true"abc".repeat(3)// "abcabcabc"Array.from(document.querySelectorAll('*'))// Returns a real ArrayArray.of(1,2,3)// Similar to new Array(...), but without special one-arg behavior[0,0,0].fill(7,1)// [0,7,7][1,2,3].findIndex(x=>x==2)// 1["a","b","c"].entries()// iterator [0, "a"], [1,"b"], [2,"c"]["a","b","c"].keys()// iterator 0, 1, 2["a","b","c"].values()// iterator "a", "b", "c"//Object copyingObject.assign(Point,{origin:newPoint(0,0)})