Tuesday, May 12, 2009

Test html code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
textarea {
width: 600px;
height: 200px;
}
</style>
</head>
<body>
<textarea id="src"></textarea>
<textarea id="desc"></textarea>
<button onclick='s()'>C</button>
<script type="text/javascript">
function c(str) {
return str.replace(/(['\\])/g, '\\$1');
}
function s() {
document.getElementById('desc').value = c(document.getElementById('src').value);
}
</script>
</body>
</html>

Monday, May 11, 2009

ie7 rtl scrollbar bug: auto scroll to the right side.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
#outer {
width: 200px;
height: 60px;
border: 1px solid red;
overflow: auto;
} #inner {
width: 1000px;
height: 20px;
background: green;
}
</style>
<script type="text/javascript">
function ch(){
var inner = document.getElementById('inner');
var outer = document.getElementById('outer');
// inner.style.backgroundColor = 'rgb(' + (gint(100) + 155) + ',' + (gint(100) + 155) + ',' + (gint(100) + 155) + ')';
outer.className = 'd' + new Date().getTime();
// alert(outer.scrollLeft);
}

function gint(i){
return parseInt(Math.random() * i);
}
</script>
</head>
<body dir="rtl">
<div id="outer">
<div id="inner" onmousedown="ch();">
Hello world!
</div>
</div>
</body>
</html>

Monday, May 4, 2009

construct array by nodefault class

Just a test for pretty.js :)

#include
#include
using namespace std;

class NoDefault {
friend ostream& operator << (ostream& os, const NoDefault& o);
private:
static unsigned _id;
unsigned id;
unsigned pid;
public:
NoDefault(char ch){
id = ++_id;
pid = 0;
cout << "NoDefault(char): " << id << endl;
}
NoDefault(const NoDefault& o) {
id = ++_id;
pid = o.id;
cout << "NoDefault(const NoDefault&): " << id << " by pid: " << o.id << endl;
}

};

unsigned NoDefault::_id = 0;

ostream& operator << (ostream& os, const NoDefault& o) {
os << "id: " << o.id << ";\tpid: " << o.pid;
return os;
}

int main() {
//! NoDefault o0; // error
NoDefault o1('1');
NoDefault o2(o1);

// cannot initialize array
//! NoDefault os0[10];

vector v0;
v0.push_back(o1);

cout << "vector<> v(n, c)" << endl;
//! vector v1(10);
vector v2(10, NoDefault('1'));

// malloc & new
//! NoDefault *op1 = new NoDefault[10];

// malloc space for 10 NoDefault objects, but not initialize it.
NoDefault *op2 = (NoDefault*)malloc(sizeof(NoDefault) * 10);
new(op2 + 1) NoDefault('c'); // initilize op2[1]
cout << op2[1] << endl;
cout << op2[0] << endl; // op2[0] is not initialized
return 0;
}