Instantly share code, notes, and snippets.

David Thingsaker davidthingsaker

View GitHub Profile
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');
@davidthingsaker
davidthingsaker / PjaxMiddleware.php
Last active Feb 1, 2018
PjaxMiddleware for Laravel Lumen - Modified from Jeffrey Way's L5.1 version
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
@davidthingsaker
davidthingsaker / datasizes.php
Created Jul 21, 2015
Human readable data sizes in PHP
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) {
@davidthingsaker
davidthingsaker / time.php
Last active Aug 29, 2015
Human readable times in PHP
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 ';
@davidthingsaker
davidthingsaker / default.vlc
Last active Jun 2, 2018
Example Varnish 4.0 Configuration
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.
@davidthingsaker
davidthingsaker / responsive mixin
Created Sep 24, 2014
SCSS / Sass mixin for responsive sites
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) {
@davidthingsaker
davidthingsaker / Vertical Center Multi-line Text
Created Jan 13, 2014
To vertically align multiple lines of text including a fix for IE7
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]
@davidthingsaker
davidthingsaker / JS Device detection
Created Dec 11, 2013
JavaScript and JQuery device detection
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()));