Blog Spot!


Simple way to connect PHP PDO to mysql database

<?php

$host    = '127.0.0.1';
$db      = 'test';
$user    = 'test';
$pass    = 'qwerty';
$charset = 'utf8mb4';

$dns = "mysql:host={$host};dbname={$db};charset={$charset}";
$opt = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false
];

$pdo = new PDO($dns, $user, $pass, $opt);

Added on 08.Aug.2018
Tags: pdo php db database sql mysql

JavaScript Design Patterns

article

Design patterns are advanced object-oriented solutions to commonly occurring software problems. Patterns are about reusable designs and interactions of objects. Each pattern has a name and becomes part of a vocabulary when discussing complex design solutions.

The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral (see below for a complete list).

In this tutorial we provide JavaScript examples for each of the GoF patterns. Mostly, they follow the structure and intent of the original pattern designs. These examples demonstrate the principles behind each pattern, but are not optimized for JavaScript.

Added on 07.Aug.2018
Tags: js design patterns vanillajs good practices

GRUB Rescue

grub rescue > ls
(hd0) (hd0,msdos5) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1) (hd1) (hd1,msdos1)
grub rescue > ls (hd0,msdos1) # try to recognize which partition is this
grub rescue > ls (hd0,msdos2) # let's assume this is the linux partition
grub rescue > set root=(hd0,msdos2)
grub rescue > set prefix=(hd0,msdos2)/boot/grub # or wherever grub is installed
grub rescue > insmod normal # if this produced an error, reset root and prefix to something else ..
grub rescue > normal

For a permanent fix run the following after you successfully boot:

sudo update-grub
sudo grub-install /dev/sdX

... where /dev/sdX is your boot drive.

askubuntu

Added on 31.Jul.2018
Tags: grub rescue linux partition

Sync directories in Linux terminal

rsync is fast and easy:

rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude

You can use --exclude multiples times.

Also you can add -n for dry run to see what will be copied before performing real operation, and if everything is ok, remove -n from command line.

stackoverflow

Added on 25.Jul.2018
Tags: nix rsync terminal sync

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

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