« Archives in August, 2008

Check username availability via AJAX with jQuery

HTML

JavaScript

Server-side check.php

jQuery odd/even selector bug?

For some reason I have not been able to identify and test, this code would not work (show the same color or same color for subsequent rows, does not seem to have a pattern):

$("#tableid tbody tr:even").addClass("even");
$("#tableid tbody tr:odd").addClass("odd");

But this does work:

$("#tableid tbody tr:nth-child(even)").addClass("even");
$("#tableid tbody tr:nth-child(odd)").addClass("odd");

Any thought?

jQuery eq() typical mistake

With all the open/close quote, you might write this code:

var i = 123;
$(":checkbox:eq(i)").removeAttr("disabled");

Since the selector string is within the quotes, the correct statement should be:

$(":checkbox:eq("+i+")").removeAttr("disabled");

vmstat – Get an overview look at your server

Get an update every one second

[root@s14 trungson]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 3  0  41200  33324   2152 1489108    0    0     4    27    0     1  5  3 91  0
 2  0  41200  33500   2152 1489108    0    0     8     0 1838  3320  8  4 88  0
 1  0  41200  31452   2152 1489176    0    0    32     0 1787  3078  7  4 89  0
 2  0  41200  33260   2152 1489176    0    0     8     0 1788  2895  6  4 90  0
 1  0  41200  33068   2164 1489164    0    0    32   768 2038  3207  7  4 87  2
 2  0  41200  33132   2168 1489228    0    0    32     0 2082  4422 10  5 85  0
 2  0  41200  35628   2172 1489360    0    0   148     0 1924  3658  8  5 86  1
 0  0  41200  34596   2172 1489360    0    0    16     0 1904  3531  8  5 87  0
 4  0  41200  28636   2172 1489428    0    0   116     0 1922  3732  9  5 85  1
 0  0  41200  33036   2180 1489488    0    0     8   860 2127  3828  8  5 86  1
 1  0  41200  32844   2180 1489488    0    0    20     0 1784  3108  7  5 88  0
 0  0  41200  32780   2180 1489556    0    0    24     0 1850  3108  7  4 88  0
 2  0  41200  32844   2180 1489692    0    0   120     0 1915  3842  9  5 85  0
 2  0  41200  26508   2180 1489828    0    0    32   376 1976  3744  8  6 86  0

From the man page:

Procs
  r: The number of processes waiting for run time.
  b: The number of processes in uninterruptible sleep.
Memory
  swpd: the amount of virtual memory used.
  free: the amount of idle memory.
  buff: the amount of memory used as buffers.
  cache: the amount of memory used as cache.
  inact: the amount of inactive memory. (-a option)
  active: the amount of active memory. (-a option)
Swap
  si: Amount of memory swapped in from disk (/s).
  so: Amount of memory swapped to disk (/s).
IO
  bi: Blocks received from a block device (blocks/s).
  bo: Blocks sent to a block device (blocks/s).
System
  in: The number of interrupts per second, including the clock.
  cs: The number of context switches per second.
CPU
  These are percentages of total CPU time.
  us: Time spent running non-kernel code. (user time, including nice time)
  sy: Time spent running kernel code. (system time)
  id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
  wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

Duplicate value under Binlog_Do_DB

If you see Binlog_Do_DB show duplicate values and you mention them only once in my.cnf. For example: db1,db2,db1,db2. You would suspect that something is reading your my.cnf twice. That would be correct as it’s a MySQL bug #20748

Some Hack Script

After my fare share of performing security audit, these are some hacking script I found, not for the purpose of hacking, but for education, analysis and prevention.

Use ethtool or mii-tool to detect problems with ethernet card

[root@s2 adserver]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
                      100baseT/Half 100baseT/Full
                      1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Full
Advertised auto-negotiation: Yes
Speed: Unknown! (0)
Duplex: Half
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000033 (51)
Link detected: yes

You can also change the interface settings with ethtool.

[root@s2 adserver]# mii-tool
eth0: negotiated 10baseT-FD, link ok

Ad Server with AJAX

Normally, JavaScript document.write is used by ad servers to write the ad code directly into the page (AdSense, AdSpeed, OpenX, etc.) To reload ads automatically without a page reload, we use AJAX with JSONP (JSON with padding). Partial content reloading uses DOM to update the content. jQuery 1.2.x has this built-in, or you can write your own library.