Full-Stack Crib-Sheet

Home / Management / Full-Stack Crib-Sheet

CSS

Vertically Center a ‘div’ inside a ‘div’

Just apply the following CSS to the inner <div>:

position: relative;
top: 50%;
transform: translateY(-50%);

Scroll Bar

::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-track-piece {
  background: #eee;
}
  
::-webkit-scrollbar-thumb {
  background: #444;
}

Angular JS

Use Controller $scope from outside Angular JS

$scope = angular.element(document.getElementById('yourControllerElementID')).scope();
    
$scope.$apply(function () {
      
  // Do you stuff here
      
});

MySQL

Date Formatting

DATE_FORMAT('2016-12-05', '%M %e, %Y')

Output: December 5, 2016

Get a list of all Columns in a Table

SELECT
  COLUMN_NAME
FROM
  information_schema.columns 
WHERE
  table_schema = 'DATABASE_NAME' and table_name = 'TABLE_NAME';

PHP

Date & Time Formatting

date("F j, Y")

Output: July 14, 2016

date("Y-m-d")

Output: 2016-07-21

date("H:i:s")

Output: 13:45:22

date("h:i:s a")

Output: 01:45:22 pm

Open Errors

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Flushing Technique

public function flushStart () {
      
  ob_end_clean();
  header("Connection: close");
  ignore_user_abort();
  ob_start();
      
}
    
public function flushEnd () {
      
  $size = ob_get_length();
  header("Content-Length: $size");
  ob_end_flush();
  flush();
      
}

Memory Limit

ini_set('memory_limit', '256M');

Compression

ob_start('ob_gzhandler');

SVN

Ignore un-versioned files (inside an existing folder):

  • Right Click the folder that you like ignore files for, go to SVN menu and click Properties.
  • Add svn:ignore with * value

Ignore versioned files:

  • svn cl ignore-on-commit database.php

Gmail

If your inbox shows unread count, though you don’t have any un-read emails, try this:

in:inbox category:{primary} label:unread

JavaScript (mixed)

Random Hex Color

'#'+Math.floor(Math.random()*16777215).toString(16);

Scroll to Hash and Highlight (jQuery)

function scrollToHashAndHighlight (hash) { // hash is in the form '#divId'

  $('html, body').animate({

    scrollTop: $(hash).offset().top - 50

  }, 2000, function () {

    $(hash).effect("highlight", {}, 3000);

  });

}

DOM Ready

document.addEventListener("DOMContentLoaded", function(event) {
  // Your code ...
});

Capture Keyboard Keys (jQuery)

$(document).keyup(function(e) {
  if (e.keyCode === 27) { /* Your code */ } // ESC
  if (e.keyCode === 37) { /* Your code */ } // LEFT
  if (e.keyCode === 39) { /* Your code */ } // RIGHT
});

Short Date

var month = ('0' + (dateObj.getMonth() + 1)).slice(-2);
var date  = ('0' + dateObj.getDate()).slice(-2);        
var year  = dateObj.getFullYear();
         
var shortDate = year + '-' + month + '-' + date;

Output: 2018-08-13

Markup Interpolation (AngularJS v1.x)

var app = angular.module('myApp', []);

app.config(function($interpolateProvider) {
  $interpolateProvider.startSymbol('[{');
  $interpolateProvider.endSymbol('}]');
});

Input: [{ firstName }]
Output: Ahsan

Leave a Reply

Your email address will not be published. Required fields are marked *