Blog Spot!


Generate random alpha-numeric string in JavaScript

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

Added on 01.Jun.2016
Tags: js random functions helpers

Lighttpd and PHP

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

Added on 31.May.2016
Tags: lighttpd server configs cfg php

Lighttpd - Mod Rewrite

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"
)

Added on 27.May.2016
Tags: lighttpd server configs cfg mod rewrite

Lighttpd - Directory Listing

Enable Directory Listings Globally:

server.dir-listing = "enable"

Set Directory Listing Encoding

dir-listing.encoding = "utf-8"

Enable directory listing only for a directory:

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

cyberciti

Added on 27.May.2016
Tags: lighttpd server configs cfg directory listing

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

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