formats

Node.js is Cancer

I found this blog post and thought how refreshing it was to see someone present a different point of view on Node.js. All you really hear is how wonderful it is and Ted Dziuba does a great job at presenting a negitive view of the ever increasing popular Node.js framework.
If there’s one thing web developers love, it’s knowing better than conventional wisdom, but conventional wisdom is conventional for a reason: that shit works. Something’s been bothering me for a while about this node.js nonsense, but I never took the time to figure it out until I read this butthurt post from Ryan Dahl, Node’s creator. I was going to shrug it off as just another jackass who whines because Unix is hard. But, like a police officer who senses that something isn’t quite right about the family in a minivan he just pulled over and discovers fifty kilos of black horse heroin in the back, I thought that something wasn’t quite right about this guy’s aw-shucks sob story, and that maybe, just maybe, he has no idea what he is doing, and has been writing code unchecked for years. Since you’re reading about it here, you probably know how my hunch turned out. Node.js is a tumor on the programming community, in that not only is it completely braindead, but the people who use it go on to infect other people who can’t think for themselves, until eventually, every asshole I run into wants to tell me the gospel of event loops. Have you accepted epoll into your heart?

A Scalability Disaster Waiting to Happen

Let’s start with the most horrifying lie: that node.js is scalable because it “never blocks” (Radiation is good for you! We’ll put it in your toothpaste!). On the Node home page, they say this:
Almost no function in Node directly performs I/O, so the process never blocks. Because nothing blocks, less-than-expert programmers are able to develop fast systems.
This statement is enticing, encouraging, and completely fucking wrong. Let’s start with a definition, because you Reddit know-it-alls keep your specifics in the pedantry. A function call is said to block when the current thread of execution’s flow waits until that function is finished before continuing. Typically, we think of I/O as “blocking”, for example, if you are calling socket.read(), the program will wait for that call to finish before continuing, as you need to do something with the return value. Here’s a fun fact: every function call that does CPU work also blocks. This function, which calculates the n’th Fibonacci number, will block the current thread of execution because it’s using the CPU.
Continue… at

Node.js is Cancer

by Ted Dziuba
 
 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

tinyMCE 3.4 IE loses focus on mouse click outside of editor, WebKit failing to focus *FIX*

I was recently involved in a project which required me to create an app that contained a WYSIWYG HTML editor and several hundred elements outside of the editor that when clicked, inserted a string at the caret position of the editor that was selected by the user. During testing Browser Compatibility bugs were found with Internet Explorer, Safari and Chrome. (Fire Fox worked as expected). Problem? -Internet Explorer lost focus on selected text range or caret position on click outside of editor.- -WebKit browsers did not focus on editor content properly on page load and any insert commands would overwrite current content.- Solution: 1: Add an init function to your tinyMCE config
1
2
3
4
5
6
7
8
9
10
/**/
function initTiny(){
// We will put some code here later }
tinyMCE.init({
// Configs ........
oninit: initTiny 
// Tell tiny to fire off this function once it is rendered });
/**/
2: Let’s update your new initTiny function with some browser detection and start fixing those pesky problems we have.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**/
/**/
/* add a new object variable to tinyMCE namespace so we can
* use it to store the caret/cursor location or a range selection
*/
tinyMCE.bookmarkLocation = '';
function initTiny(){
/* ed is now the activeEditor instance */
var ed = tinyMCE.activeEditor;
/* Detect if the Browser is Internet Explorer */
if(tinyMCE.isIE){
/* Force IE to focus on the editor after page load.*/
tinymce.execCommand('mceFocus',false, ed.editorId);
/* Set the bookmarkLocation to the current bookmark location.
* location. (We told IE to focus using the prev command so
* the bookmark will be the first element) */
tinyMCE.bookmarkLocation =ed.selection.getBookmark(2, true); 
/* Create an event listener that sets the new bookmark location
* every time the editor is clicked on. The event listener will
* even record a text range selection. */
tinymce.dom.Event.add(ed.getDoc(), 'click', function (e) {
tinyMCE.bookmarkLocation = ed.selection.getBookmark(); });
}
/* Detect if the Browser is WebKit eg: Safari, Chrome */
if(tinyMCE.isWebkit){
/* Force the Browser to focus on the last child of the editor.. 
* since Safari defaults the focus on the Iframe then the last
* child will be the first element of the editor because tiny will
* wrap the iframe html in its own body you just don't see it */
tinyMCE.activeEditor.selection.setCursorLocation( tinyMCE.activeEditor.getBody().lastChild,
1); } }
3. Update your click events
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* IE is the only one that really needs the bookmarkLocation */
if(tinyMCE.isIE)
// Set the bookmark location in the editor
tinyMCE.activeEditor.selection.moveToBookmark(tinyMCE.bookmarkLocation);
// Update the editor with your new content a that location
tinyMCE.activeEditor.selection.setContent('My String');
// Update the bookmark with the new location which is now AFTER the text that was inserted
tinyMCE.bookmarkLocation = tinyMCE.activeEditor.selection.getBookmark(2, true);
}else{
tinyMCE.execInstanceCommand(tinyMCE.activeEditor.editorId, 'mceInsertContent', false, 'My String');
}
/**/
That’s it now everything should work.  

Also Check out

Stack Overflow: Preserve caret/bookmark position in tiny while using setContent

TinyMce: TinyMCE::getBookmark()

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
1 Comment  comments 
© Jeff Cobb
credit