Blog Spot!


Twitter Bootstrap - Tabs - change URL's hash

Enable hash in the url for routing in Backbone when using bootstrap tabs

Try this code. It adds tab href to url + opens tab based on hash on page load:

$(function(){
  var hash = window.location.hash;
  hash && $('ul.nav a[href="' + hash + '"]').tab('show');

  $('.nav-tabs a').click(function (e) {
    $(this).tab('show');
    var scrollmem = $('body').scrollTop() || $('html').scrollTop();
    window.location.hash = this.hash;
    $('html,body').scrollTop(scrollmem);
  });
});

stackoverflow

Added on 29.Mar.2017
Tags: bootstrap backbone tabs tab hash url

JavaScript pub-sub pattern, event emitter made simple

Pub-Sub pattern:


var events = {
    events: {},

    on: function (eventName, fn) {
        this.events[eventName] = this.events[eventName] || [];
        this.events[eventName].push(fn);
    },

    off: function(eventName, fn) {
        if (this.events[eventName]) {
            for (var i = 0; i < this.events[eventName].length; i++) {
                if (this.events[eventName][i] === fn) {
                    this.events[eventName].splice(i, 1);
                    break;
                }
            }
        }
    },

    emit: function (eventName, data) {
        if (this.events[eventName]) {
            this.events[eventName].forEach(function(fn) {
                fn(data);
            });
        }
    }
};

Added on 28.Mar.2017
Tags: js events pub-sub functions

Vim config file default settings

use or create ~/.vimrc

inside put:

" colour
syntax on

" show line numbers
"set nu

" tab size
set tabstop=4

" indent lines
set listchars=tab:\¦\
set list

Added on 24.Mar.2017
Tags: vim config

Convert decimal to hex in JavaScript

Convert to HEX with prepad

function toHex(i, pad) {

  if (typeof(pad) === 'undefined' || pad === null) {
    pad = 6;
  } 

  var strToParse = i.toString(16);

  while (strToParse.length < pad) {
    strToParse = "0" + strToParse;
  }

  return strToParse;
}

console.log(toHex(572886, 6));

Added on 23.Mar.2017
Tags: prepadding js pad functions

Generic simple nginx server config

server {
        listen 3000 default_server;
        listen [::]:3000 default_server;
        server_name redis.donvercety.biz;

        index index.html index.htm index.php;

        root /var/www/html/redis;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

}

Added on 22.Mar.2017
Tags: server nginx generic

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