Blog Spot!


Basic vanilla JavaScript inheritance

Basic:

var Device = function(opt) {
  this.id = opt.id;
  this.type = opt.type;
};

Device.prototype.getId = function() {
  return this.id;
};

Device.prototype.getType = function() {
  return this.type;
}

var Relay = function(opt) {

  // call the inherited constructor
  Device.call(this, opt);

  this.code = opt.code;
};

Relay.prototype.getCode = function() {
  return this.code;
};

// Relay will inherit Device 
Relay.prototype = Object.create(Device.prototype);

var device = new Relay({id: 123, type: 'test', code:'RL-01'});

console.log(device);
console.log(device instanceof Device); // true
console.log(device instanceof Relay);  // true

With some more structure:

var Device = (function() {

    function F(opt) {
        this.id = opt.id;
        this.type = opt.type;
    }

    F.prototype.getId = function() {
        return this.id;
    };

    F.prototype.getType = function() {
        return this.type;
    }

    return F;
}());

var Relay = (function() {

    function F(opt) {
        // call the inherited constructor
        Device.call(this, opt);

        this.code = opt.code;
    }

    F.prototype.getCode = function() {
        return this.code;
    }

    // Relay will inherit Device 
    F.prototype = Object.create(Device.prototype);

    return F;
}());

var device = new Relay({id: 123, type: 'test', code:'RL-01'});

console.log(device);
console.log(device instanceof Device); // true
console.log(device instanceof Relay);  // true

Added on 24.Jul.2018
Tags: inheritance js javascript vanilla class

Simple vanilla JavaScript ajax

function ajaxGet(url, cb){
    var req = new XMLHttpRequest();

    req.onload = function() {
        cb(req.status, req.response);
    };

    req.open("GET", url);
    req.send();
}

ajaxGet('https://httpbin.org/get', function(status, res) {
    console.log(status , JSON.parse(res));
})

Added on 23.Jul.2018
Tags: ajax js vanilla javascript simple

Delete files older than X days

stackoverflow

find is the common tool for this kind of task:

find ./my_dir -mtime +10 -type f -delete

EXPLANATIONS

  • ./my_dir your directory (replace with your own)
  • -mtime +10 older than 10 days
  • -type f only files
  • -delete no surprise. Remove it to test your find filter before executing the whole command!

And take care that ./my_dir exists to avoid bad surprises!

Added on 19.Jun.2018
Tags: bash shell terminal linux delete logs files

Laravel Equivalent In JavaScript - as of 2017

We have 3 major JavaScript alternatives to Laravel:

article

Added on 06.Jun.2018
Tags: js javascipt laravel mvc framework

Enable SSH after fresh Apache2 or LAMP install

To achieve this, ssl module has to be enabled and apache needs to be told, how to handle traffic from port 443, this is done by enabling default-ssl site.

$ sudo a2enmod ssl
$ sudo a2ensite default-ssl
$ sudo service apache2 restart

Firewall

If you have firewall enabled, you should allow incoming TCP connection on port 443.

$ sudo ufw allow 443/tcp

article

Added on 11.May.2018
Tags: apache ssh server linux ssl

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