Skip to content

Instantly share code, notes, and snippets.

@davidthingsaker
davidthingsaker / datatables.js
Last active March 17, 2016 15:31
Datatables class
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 February 1, 2018 19:24
PjaxMiddleware for Laravel Lumen - Modified from Jeffrey Way's L5.1 version
<?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 July 21, 2015 10:17
Human readable data sizes in 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 August 29, 2015 14:25
Human readable times in 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 October 9, 2023 14:58
Example Varnish 4.0 Configuration
#########################################################################
# 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 September 24, 2014 16:13
SCSS / Sass mixin for responsive sites
$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 }
@davidthingsaker
davidthingsaker / Joomla Varnish default.vcl
Created February 4, 2014 13:26
Joomla Varnish config
#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 January 13, 2014 11:21
To vertically align multiple lines of text including a fix for IE7
.textBox {
position: relative;
height: 100%;
}
.inner {
position: absolute;
display: table;
width: 100%;
height: 100%;
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 December 11, 2013 16:25
JavaScript and JQuery 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()));