Use of CSS constants in script.

In Sciter you can define CSS constants using @const declarations like this: <style> @const TEST_STR:”test”; @const TEST_COLOR: rgb(128,0,0); @const TEST_NUMBER: 128; </style> and use them not only in CSS ( as @TEST_COLOR for example ) but also in script using accessor like this: var test_str = self.style.constant(“TEST_STR”); If you think that self.style.constant is too narrative…

What does “::” construction mean in TIScript?

Got this question in one of emails… One of forms to declare anonymous function in TIScript is so called single statement lambda function: ‘:’ [param-list] ‘:’ <statement>; Let’s say we have this JavaScript code: var counter = 0; var inc = function() { counter++; } So each time when you call inc() the counter will…

Comments in source code considered harmful

In the file ResourceFontFileLoader.h (offical Windows SDK samples) you can see variable declared as: static IDWriteFontFileLoader* instance_; As you see it is a raw pointer here. And in the file ResourceFontFileLoader.cpp it is initialized with this: // Smart pointer to singleton instance of the font file loader. IDWriteFontFileLoader* ResourceFontFileLoader::instance_( new(std::nothrow) ResourceFontFileLoader() ); Note the comment….

Question on interview: diameter of binary tree.

I got a task on interview to calculate diameter of given binary tree. While I don’t like to solve abstract problems ( I have a lot of problems to solve in my projects already) I’ve found this one particularly interesting as it actually has practical value in one of algorithms on DOM tree (that is…

boost.coroutine vs my $generator.

Today I saw discussion about boost.coroutine on gmane: Generators and coroutines are conceptually the same feature and I have implementation of $generator thing that can be used to implement coroutines. My implementation is of 15 lines of code and does not require any threads/fibers and so context switches – pure C++ with macro magic, pretty…

The KiTE – template engine for JavaScript

Preface Modern Web applications frequently use AJAX kind of client/server interaction. They receive data from the server in pure JSON format. That means instead of generating markup on the server such applications are composing HTML inside the browser (on client side). Straightforward approach is to use string concatenation spagetti like : "<b>" + data +…

Behaviors, simple jQuery extension.

Behaviors as an entity is a declarative way to assign/bind scripting methods to DOM elements. We can think that browsers have following declarations in their default CSS declarations: input[type=text] { binding: TextEditorImpl; } input[type=button] { binding: ButtonImpl; } select { binding: SelectImpl; } … So when we define <input type="text" /> in our markup we…

C++, how to change class of object in runtime.

There is a nice feature in TIScript that allows to change class of already instantiated object. Let’s say we have two classes: class MyWidget : Behavior { … } class MyWidgetReadonly : Behavior { … } that handle user interaction with some widget on the screen. This widget can operate in two distinct modes: normal…