Blog Spot!


Extending a Linux File System after Resizing the Volume

Expand the modified partition using growpart.

1: sudo growpart /dev/xvdf 1

Use a file system-specific command to resize each file system to the new volume capacity.

For a Linux ext2, ext3, or ext4 file system, use the following command, substituting the device name to extend:

2: sudo resize2fs /dev/xvdf1

full docs.aws

Added on 07.Nov.2017
Tags: amazon aws volume expanded resize linux hdd disk

Calculate percentage

((input - min) * 100) / (max - min)

stackoverflow

Added on 06.Nov.2017
Tags: percentage min max % avarage

Dependency injection container in JavaScript

Good article

Singleton DI Container in JS

var container = {

  dependencies: {},

  register: function(key, value) {
    this.dependencies[key] = value;
  },

  resolve: function(deps, func, scope) {
    scope = scope || {}; scope.container = {};

    for (var i = 0; i < deps.length; i++) {
      scope.container[deps[i]] = this.get(deps[i]);
    }

    return function() {
      func.apply(scope || {}, Array.prototype.slice.call(arguments, 0));
    };
  },

  get: function(dependency) {
    if (this.dependencies[dependency]) {
      return this.dependencies[dependency];
    }
    throw new Error('Unable to find dependency ' + dependency);
  }
};

How to use:

container.register('service', function() {
  return { name: 'Service' };
});

container.register('router', function() {
  return { name: 'Router' };
});

// adding dependencies when registrating dependency
container.register('test', function() {
  this.service = container.get('service');
  console.log(this.service().name === 'Service');
  return 'yo';
});

var start = container.resolve(['service', 'router', 'test'], function(other) {

  try {
    console.log(this.container.service().name === 'Service');
    console.log(this.container.router().name === 'Router');

    console.log(this.container.test());
    console.log('DONE');

  } catch (ex) {
    console.log(ex);
  }
});

start("Other");

Added on 18.Oct.2017
Tags: di dependency injection js

Get total read and total write IOPS in Linux

iostat -d <disk_name> | grep <disk_name> | awk '{ print $2; }' - avarage IOPS

iostat -dx <disk_name> | grep <disk_name> | awk '{ print $4; }' - Reads/sec

iostat -dx <disk_name> | grep <disk_name> | awk '{ print $5; }' - Writes/sec

unix.stackexchange

Added on 14.Sep.2017
Tags: iostat iops reads writes statistics

PHP Curl functions

function makeGetRequest($url, $headers) {
    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1, // return the transfer as a string
        CURLOPT_FAILONERROR    => 0, // response code greater than 400 cause error
        CURLOPT_HEADER         => 1, // show curl response headers
        CURLOPT_HTTPHEADER     => $headers,
        CURLOPT_URL            => $url,
        CURLOPT_CONNECTTIMEOUT => 10, // should only spend 10 seconds attempting to connect
        CURLOPT_TIMEOUT        => 30, // hould only spend a maximum of 30 seconds executing the request
    ));

    $resp = curl_exec($curl);

    curl_close($curl);
    return $resp;
}

function makePostRequest($url, $headers, $body) {
    $curl = curl_init();

    curl_setopt_array( $curl, array(
        CURLOPT_RETURNTRANSFER => 1, // return the transfer as a string
        CURLOPT_FAILONERROR    => 0, // response code greater than 400 cause error
        CURLOPT_HEADER         => 1, // show curl response headers.
        CURLOPT_HTTPHEADER     => $headers,
        CURLOPT_URL            => $url,
        CURLOPT_POST           => 1,
        CURLOPT_POSTFIELDS     => $body,
        CURLOPT_CONNECTTIMEOUT => 10, // should only spend 10 seconds attempting to connect
        CURLOPT_TIMEOUT        => 30, // hould only spend a maximum of 30 seconds executing the request
    ));

    $resp = curl_exec($curl);

    curl_close($curl);
    return $resp;
}

Added on 01.Sep.2017
Tags: php function curl handler get post rest

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