Blog Spot!


How to get the value of a bit at a certain position using JavaScript

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;
}

catonmat

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);
}

stackoverflow

&   - bitwise and
|   - bitwise or
^   - bitwise xor
~   - bitwise not
<< - bitwise shift left
>> - bitwise shift right

catonmat

Added on 26.May.2016
Tags: js bit manipulation bitwise operations bits

Error Handling in Node.js

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.

joyent

Added on 25.May.2016
Tags: js errors nodejs design patterns

MySQL Create Database with UTF8 Character Set Syntax

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;

Added on 20.May.2016
Tags: sql mysql create

Sending messages in linux terminal

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

superuser

Added on 14.May.2016
Tags: linux terminal wall message

How to run a command in the background with a delay?

(sleep 300; echo "80" > /sys/class/leds/blue/brightness) &

stackexchange

Added on 14.May.2016
Tags: linux cmd delay background terminal

Search


PHP Libraries


Carbon lib / docs
Idiorm lib / docs
Image Workshop lib / docs
lorenzos/Minixed lib / docs
Parsedown lib / docs
PHP Paginator lib / docs
PHP Redis lib / docs
QrCode lib / docs
Requests lib / docs
Slim lib / docs
Spyc lib / docs
TWIG lib / docs
Upload lib / docs
Validation lib / docs
Zebra Image lib / docs

JS Libraries


AJV lib / docs
BackboneJS lib / docs
Bootstrap Notify lib / docs
C3.js lib / docs
ChartJS lib / docs
FastMD5 lib / docs
HighlightJS lib / docs
jQuery-Storage lib / docs
JS-Cookie lib / docs
Leaflet JS lib / docs
LowDB lib / docs
Marked lib / docs
NeedlyJS lib / docs
ParcelJS lib / docs
RequireJS lib / docs
Swig lib / docs
Toastr lib / docs
Underscore lib / docs
ValidateJS lib / docs
top