jQuery: Identifying selectors, that represent the same DOM node.

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)

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading...

A fact about JavaScript parseInt() that i wasn’t aware of, or why web projects sometimes break on August

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”

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
Loading...

Getting gettext to work in Apache on windows

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”

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.50 out of 5)
Loading...

The danger of: foreach ($array as &$v)

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)”

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Wamp: installing both PHP 4 and 5 and how to switch them back and forth

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”

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading...

MySQL: best practices

This post will contain several tips, for working with MySQL: how to import data to an empty MySQL database faster and also how to fetch data from queries in ways, that are likely to produce less errors.
Continue reading “MySQL: best practices”

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Asynchronous http GET requests with PHP

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”

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.50 out of 5)
Loading...

WordPress for now

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.

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.25 out of 5)
Loading...