<a href=”javascript:void(0);” onclick=”alert(‘I\’m Huy (\x22huypv.net\x22)’)”>Alert</a>
Explain:
\x22 ~ double quote character ”
Hexa: 22 -> Decimal: 2*16+2 = 34 = char code of double quote
<a href=”javascript:void(0);” onclick=”alert(‘I\’m Huy (\x22huypv.net\x22)’)”>Alert</a>
Explain:
\x22 ~ double quote character ”
Hexa: 22 -> Decimal: 2*16+2 = 34 = char code of double quote
Ảnh bên trái là lúc đầu tiên load trang. Ảnh bên phải là khi cuộn trang xuống một phần.
Khi thanh scroll bar cuộn lên/xuống thì quảng cáo cũng cuộn theo tương ứng.
Công thức:hay
Trong đó:
d1 = $(document).scrollTop()
h = $(window).height();
H = $(document).height();
ha = $(‘#advertiseId’).height();
Khi có sự kiện cuộn trang (window.onscroll) thì cứ tính d2 và gán lại top cho quảng cáo bằng Math.floor(d2) + ‘px’ là được.
Problem
memcache_set is not atomic function
Cache news:
Key = news_134 (134 is news id)
Value = array(‘id’ => 134, ‘title’ => ‘huypv is a web developer’, ‘sapo” => ‘bla bla’, …., ‘view_count’ => 134);
When have guests read news 134 at the same time, the view_count is updated but not correct!
Solution
Create function updateViewCount and make it is atomic
function updateViewCount($id, $inc = 1) {
global $objMemcacheConnId;
$timeout = 15; // TODO change for your scene
$cacheKey = ‘news_’ . $id;
$lockKey = $cacheKey . ‘.lock’;
$getLock = memcache_add($objMemcacheConnId, $lockKey, 1, false, $timeout);
while (!$getLock) {
$getLock = memcache_add($objMemcacheConnId, $lockKey, 1, false, $timeout);
$nbTry++;
usleep(1); // micro second. 1 second = 10^6 micro second (1 milion)
if ($nbTry >= $timeout * 1000000) break;
}
if ($getLock) {
$currentNews = memcache_get($objMemcacheConnId, $cacheKey);
if ($currentNews) {
$newNews = $currentNews;
$newNews[‘view_count’] += $inc;
memcache_set($objMemcacheConnId, $cacheKey, $newNews);
memcache_delete($objMemcacheConnId, $lockKey); # release lock
return true;
} else {
return false; # not found
}
} else {
return false; # timeout
}
}
How to test? Does it work?
Use ab (apache benchmark) or multiple curl to send concurrent request.
# insert multiple records
INSERT INTO my_table (column_1, column_2, …) VALUES (value_1, value_2), (value_11, value_12), …
# update???
UPDATE news
SET title = CASE id
WHEN 13 THEN ‘New title for #1’
WHEN 74 THEN ‘New title for #74’
END, content = CASE id
WHEN 13 THEN ‘New content for #13’
WHEN 74 THEN ‘New content for #74’
END, updated=NOW()
WHERE id IN (13, 74);
<div> Link to call:<br /> <a href="wtai://wp/mc;097529xxxx">Call me</a> </div> <div> Link to SMS:<br /> <a href="sms:097529xxxx?body=Noi dung tin nhan khong dau">Send SMS</a> </div> <div> Add phone book:<br /> <a href="wtai://wp/ap;097529xxxx;Anonymous">Add contact</a> </div>