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
Error handling is a pain, and it's easy to get by for a long time in Node.js without dealing with many errors correctly. But building robust Node.js apps requires dealing properly with errors, and it's not hard to learn how.
Create table
CREATE DATABASE `mydb` CHARACTER SET utf8 COLLATE utf8_general_ci;
Add user Access
GRANT ALL ON `mydb`.* TO `username`@localhost IDENTIFIED BY 'password';
Add user Access - FULL CONTROL
GRANT ALL PRIVILEGES ON *.* TO 'username'@'192.168.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Flush Privileges
FLUSH PRIVILEGES;
Usage from man wall:
wall [file]
Wall displays the contents of file or, by default, its standard input
simple usage:
$ echo "who's out there" | wall
for bigger text messages:
$ wall << .
who is out there?
.
This would be a "useless use of here documents", because by default the terminal itself will be connected to wall's standard input and wall will start reading from it until it receives an end-of-file character (Ctrl+D):
$ wall
who is out there?
^D
(sleep 300; echo "80" > /sys/class/leds/blue/brightness) &