By Kipras on April 13, 2011
If you have two jQuery selectors, that each represent a single DOM node,
and you need to know whether it is the same DOM node, you can easily do this with:
var selector1 = $('#some_item');
var selector2 = $('#some_item');
if (selector1[0] == selector2[0])
{
// Do stuff if the selectors represent the same DOM node
}
This compares the inner DOM nodes (NOT the jQuery wrapper objects) and there cannot be two different objects representing the same DOM node in memory at the same time, thats why this works. Whereas there can be two different jQuery wrappers for the same DOM node, thats why if (selector1 == selector2)
will work only some times.
What [0] at the end of the selector does, is it fetches the inner DOM node, that the jQuery object wraps around. There is another way to retrieve it from the jQuery object: selector1.get(0)
This works across all major browsers (Firefox, Chrome, Opera, IE)

Loading...
Posted in Programming | Tagged dom, jquery, selectors |
By Kipras on August 4, 2009
JavaScript, is a really, REALLY cool and powerful language (especially if used correctly), and i intend to write about it a lot in the future.
Bur right now, i want to mention a fact about JavaScript parseInt(), that i wasn’t aware of.
Continue reading “A fact about JavaScript parseInt() that i wasn’t aware of, or why web projects sometimes break on August”

Loading...
Posted in Programming | Tagged JavaScript, octal, parseInt(), radix |
By Kipras on August 4, 2009
Gnu gettext is a widely used translation system, used to translate software projects and make them available in different languages. Many big web projects use it, like WordPress for example. It works well and is rather easy to use, for both programmers and translators (except for the fact that you need to restart your http server every time the translation files change..). Using it also eliminates any need to write custom translation mechanisms yourself.
But there is a drawback for PHP developers, working on windows machines, who want to use gettext: you can’t change locale on Windows (not with the standard methods that is).
Continue reading “Getting gettext to work in Apache on windows”

Loading...
Posted in Programming | Tagged apache, gettext, php, windows |
By Kipras on May 28, 2009
This will be a short post, concerning one problem that can easily arise from the incorrect usage of PHP’s foreach cycle’s ability to pass each array item by reference instead of by value. I ran into this problem a little while ago and it caused me roughly about an hour of general wondering of why the stupid script just doesn’t work.
Continue reading “The danger of: foreach ($array as &$v)”

Loading...
Posted in Miscellaneous |
By Kipras on May 6, 2009
This post will be for Wamp server users. I will explain, how to have both PHP 4 and 5 installed, and switch them at any time.
Wamp server is a brilliant tool for web developers (sadly it is Windows-only). It takes care of installing the big 3 (so you don’t have to do it manually):
- Apache web server
- PHP scripting language module for Apache
- MySQL database server
Continue reading “Wamp: installing both PHP 4 and 5 and how to switch them back and forth”

Loading...
Posted in Programming | Tagged php 4, php 5, switching, wamp, windows |
By Kipras on March 21, 2009
I’ve stumbled upon a problem recently – how do you execute slow blocks of code, without locking your script?
The simple answer is – you can’t. At least, not with PHP. In languages like Java or C, where you can use threads (multiple program code blocks, running asynchronously (at the same time)), this is possible to achieve, by simply dispatching another thread, and have your previous one continue to do it’s work. However, PHP doesn’t have threads.
Continue reading “Asynchronous http GET requests with PHP”

Loading...
Posted in Programming | Tagged asynchronous, curl, php |
By Kipras on March 18, 2009
I’ve discovered the internet :)
I’m Kipras Mancevičius, a programmer (currently web developer) from Lithuania. Fancy intro.
From now on this blog should be the place, where i will post random (or not so random) thoughts about common programming problems, and (hopefully) ways to solve them.
I will also post stuff lying around the internet that i discover and find interesting here too (hopefully someone else will also find it interesting).
WordPress will do for now, but in the near future i plan to bring a more.. personal touch to this place :)
Generally, if this will be of any use to anyone, then good.

Loading...
Posted in Miscellaneous | Tagged about |