function randString(length) {
var text = "", data = "", len, i;
data += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
data += "abcdefghijklmnopqrstuvwxyz";
data += "0123456789";
len = parseInt(length);
if (isNaN(len)) {
len = 8;
}
for (i=0; i < len; i++)
text += data.charAt(Math.floor(Math.random() * data.length));
return text;
}
console.log(randString(5));
// with fixed length
function randString() {
return Date.now().toString(36) + Math.random().toString(32).substr(1);
}
Install the packages we need: (this may not be all, but these two will automatically download the rest as dependencies)
sudo apt-get install lighttpd php5-cgi
Enable the fastcgi module and the php configuration with
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
Reload the lighttpd daemon
sudo service lighttpd force-reload
Server Module mod_rewrite
needs to be selected
server.modules = (
"mod_rewrite",
)
Rewrite rule similar to apache 2 mod_rewrite
rules
url.rewrite-if-not-file = (
"^/users(.*)$" => "users/index.php/$1"
)
server.dir-listing = "enable"
dir-listing.encoding = "utf-8"
For example, display directory listing only for /files/
$HTTP["url"] =~ "^/files($|/)" {
server.dir-listing = "enable"
dir-listing.encoding = "utf-8"
}
...then do:
/etc/init.d/lighttpd restart
var num = 8888, dat = "";
/**
* Returns bit value
*/
function getBit(num, pos) {
return (num >> pos) & 1;
}
for (var i = 0; i < 16; i++) {
dat += getBit(num, i)
}
console.log(reverse(dat) == "0010001010111000");
function reverse(s) {
var o = '';
for (var i = s.length - 1; i >= 0; i--) {
o += s[i];
}
return o;
}
Other useful bit stuff
/**
* Returns boolean
*/
function testBit(num, bit){
return ((num >> bit) % 2 != 0)
}
/**
* Set bit to given value
*/
function setBit(num, bit){
return num | 1 << bit;
}
/**
* Clear bit, set it to 0
*/
function clearBit(num, bit){
return num & ~(1 << bit);
}
/**
* Toggle bit 0/1
*/
function toggleBit(num, bit){
return testBit(num, bit)?clearBit(num, bit):setBit(num, bit);
}
&
- bitwise and
|
- bitwise or
^
- bitwise xor
~
- bitwise not
<<
- bitwise shift left
>>
- bitwise shift right