Instantly share code, notes, and snippets.

View datatables.js
function Datatable(table){
this.table = table;
this.dataKeys = $(this.table).data('columns');
this.buildDatatable();
}
Datatable.prototype.options = function(){
var options = {};
options.table = $(this.table).data('model');
options.scope = $(this.table).data('scope');
View PjaxMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\DomCrawler\Crawler;
class PjaxMiddleware
View datasizes.php
# Pass in the level of accuracy and optionally if you are talking about speed. Which will add a per seconds suffux.
public static function human_datasize($bytes, $decimals = 2, $speed = false)
{
$sz = 'BKMGTP';
if(is_null($bytes)) {
return 'Unlimited';
}
if ($speed) {
View time.php
# Set a timestamp to time, e.g. 2 months
public static function time_ago($timestamp)
{
$years = floor($timestamp / 31536000);
$days = floor(($timestamp - ($years*31536000)) / 86400);
$hours = floor(($timestamp - ($years*31536000 + $days*86400)) / 3600);
$minutes = floor(($timestamp - ($years*31536000 + $days*86400 + $hours*3600)) / 60);
$timestring = '';
if ($years > 0){
$timestring .= $years . ' years ';
View default.vlc
#########################################################################
# This is an example VCL file for Varnish 4.0. #
# From: https://gist.github.com/davidthingsaker/6b0997b641fdd370a395 #
# LICENSE: If this could help you in any way, you are obliged to use it #
# for free with no limitations. #
#########################################################################
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
View responsive mixin
$small-desktop: 960px;
$large-desktop: 1200px;
$handheld: 768px;
$handhelds-landscape: 1024px;
$mobile: 640px;
$mobile-landscape: 480px;
@mixin respond-to($media) {
@if $media == largeDesktop {
@media only screen and (min-width: $large-desktop) { @content }
View Joomla Varnish default.vcl
#I did not create this, all credit to those that did. I am simply storing it here for my own use original URL:
#http://www.stardothosting.com/blog/2011/08/varnish-caching-with-joomla/
# Place the following 2 configuration blocks right after your "backend default {…}" block
# inside your /etc/varnish/default.vcl file (the main Varnish configuration file)
# This Varnish configuration makes use of a custom HTTP header to determin whether
# some user is logged in or not inside Joomla! To allow this, simply append this code
# // Set user state in headers
# if (!$user->guest) {
View Vertical Center Multi-line Text
.textBox {
position: relative;
height: 100%;
}
.inner {
position: absolute;
display: table;
width: 100%;
height: 100%;
View Laravel-Heroku HTTP Auth
Create an .htaccess file in the webroot:
AuthUserFile /app/www/public/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
Create a .htpasswd file:
htpasswd -c /app/www/public/.htpasswd [username]
View JS Device detection
// JavaScript
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}
// JQuery
$.browser.device = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));