Skip to main content

Posts

Showing posts from May 11, 2012

CoffeeScript-like language written in Python

Are there any languages targeting JavaScript (like CoffeeScript) and written in Python? I found Pyjamas , but it’s GWT of Python as I see. I want a language that doesn’t need heavy runtime library and is able to be compiled to JavaScript. I found Mascara also, and it very satisfies my requirements except it’s license. CoffeeScript is ideal for me except it’s written in CoffeeScript itself. I have to compile [CoffeeScript-like language] source codes into JavaScript statically in Python application.

Jquery UI slider how to make a box follow the handler?

I am trying to create a div that should follow the handler as it is seen here: http://m1.dk/Priser/#tab:#calc,#abb

Comparing the performance of $("#foo .bar”) and $(".bar”, "#foo”)

Scroll down for the getById.getByClassName vs. qSA comparison! If we wanted to select all elements of class "bar" which are inside the element with the ID "foo" , we could write this:

Is there a way to set a Web Worker to low priority?

I am thinking of using Web Workers to provide some background functionality while a user is browsing my website (that's what Web Workers are for, right?). However, I don't want to take the risk of compromising the user experience by causing laggy scrolling, unresponsive controls, etc. Web Workers are mapped on OS threads, hence I would expect some control on the priority of these threads however, as far as I know, there's no such thing in the current API. Do you know a how to accomplish this? Even with a hack?

Is it possible to change text color based on background color using css?

Is it possible to change text color based on background color using css?

Memory leaks in JavaScript: What are they, how to spot them, how to create them

I've just been helping out with some interviews for a new developer and JavaScript is a major part of my role and the role we're recruiting for. To be honest the candidate wasn't that good and he didn't really understand JavaScript however in the interview he confused JavaScript with C# and started to discuss memory leaks in JS. I wanted to intervene however it was at that point I realised how little I know about memory leaks in JS apart from the fact they use up lots of memory and slow things down.

Dojo require() and AMD (1.7)

I'm having a heckuva time transitioning to Dojo and the new AMD structure, and I'm really hoping someone can shed some light on the whole concept. I've been living on Google for the last few weeks trying to find information on not the usage, but the structure and design pattern trends in using this.

function* in JavaScript

In this page I found a new JavaScript function type: // NOTE: "function*" is not supported yet in Firefox. // Remove the asterisk in order for this code to work in Firefox 13 function* fibonacci() { // !!! this is the interesting line !!! let [prev, curr] = [0, 1]; for (;;) { [prev, curr] = [curr, prev + curr]; yield curr; } }

Databinding in angularjs

Could someone explain me how databinding works in angularjs framework? I haven't found technical details on their site . It's more or less clear how it works when data is propagated from view to model. But how angularjs tracks changes of model properties without setters and getters. I found that there is javascript watchers that may do this work. But they are not supported in IE 6 and 7. So how angularjs knows that I changed e.g.:

For loop Variations in javascript

In this website there are a list of for loop variations. I can understand the usage of for(var i=0, len=arr.length; i<len ;i++) loop (where arr is an array), since the arr.length isnt calculated every step there is marginal performance gain. However what are the advantages of using the other variants? For instance loops like

How to emulate Event.timeStamp

Event.timeStamp The timeStamp attribute must return the value it was initialized to. When an event is created the attribute must be initialized to the number of milliseconds that has passed since 00:00:00 UTC on 1 January 1970.

How does header() work?

A little context: I needed to run PHP scripts in a browser, but I didn't want to go to all the trouble of installing a server and suffer the overhead of running a server on my computer and all the stuff that goes with it, including firewalls, blah blah blah.

My alernative to nested sets for arbitrary-depth hierarchical data sets: Good or Bad?

While recreating my CMS, I wanted an alternative to the traditional parent/child approach for managing the sitemap / page hierarchy. I had remembered seeing the nested set model a while back, but couldn't remember what it was called. So, I stumbled upon a similar approach that I want to evaluate and compare the properties, making sure I won't run into dumb limitations later on because I didn't go with what is already time-tested. So, please advise if A) it's already been invented (what's it called?!), B) there are fundamental flaws in the properties, or C) it's a good approach (please give good justification!).

When to use strtr vs str_replace?

I'm having a hard time understanding when strtr would be preferable to str_replace or vice versa. It seems that it's possible to achieve the exact same results using either function, although the order in which substrings are replaced is reversed. For example: