Skip to content

Instantly share code, notes, and snippets.

View paulund's full-sized avatar

Paulund paulund

View GitHub Profile
@paulund
paulund / css-purge-webpack-config.js
Last active April 7, 2023 10:02
Using CSS Purge With Laravel Mix. Tutorial on how to use the following can be found https://paulund.co.uk/reduce-css-file-size-with-css-purge reduced a production ready CSS file from 179kb to 7.9kb.
mix.webpackConfig({
plugins: [
new purgeCss({
paths: glob.sync([
path.join(__dirname, 'resources/views/**/*.blade.php'),
path.join(__dirname, 'resources/assets/js/**/*.vue')
]),
extractors: [
{
extractor: class {
@paulund
paulund / HomeController.php
Last active November 15, 2017 08:24
Tutorial on how to use can be used https://paulund.co.uk/creating-view-classes-in-laravel. A gist to demo how to implement view objects in Laravel. Return this object from your controllers and you can remove duplicate return view code from your multiple controllers.
<?php
namespace App\Http\Controllers;
use App\Http\Resources\PostIndexResource;
use Dappa\Blog\Repositories\PostRepository;
/**
* Homepage controller
*/
class HomeController extends Controller
@paulund
paulund / php7-array-iteration.php
Created October 27, 2017 12:18
PHP7 Array Iteration
<?php
function loopThroughArrayErrors($array)
{
foreach($array['values'] as $key => $value)
{
echo $value;
}
}
function loopThroughArray($array)
@paulund
paulund / phpcs.xml
Created August 20, 2017 16:50
PHP PSR-2 CodeSniffer Config for Laravel
<?xml version="1.0"?>
<ruleset name="Laravel Standards">
<!--
The name attribute of the ruleset tag is displayed
when running PHP_CodeSniffer with the -v command line
argument. The description tag below is not displayed anywhere
except in this file, so it can contain information for
developers who may change this file in the future.
-->
@paulund
paulund / laravel-db-debug.php
Created July 18, 2017 17:30
Laravel Output DB Debug
/**
* Add the following to routes to output DB data
*/
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
echo'<pre>';
echo $query->sql;
var_dump($query->bindings);
var_dump($query->time);
echo'</pre>';
});
@paulund
paulund / youtube-responsive.css
Created July 16, 2017 09:45
Responsive Youtube Embedded Video
.video-wrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
.video-wrapper iframe {
position: absolute;
top: 0;
@paulund
paulund / javascript-slugify.js
Created July 4, 2017 20:20
JavaScript function to slugify a string
slugify (text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/&/g, '') // Replace & with empty
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
.replace(/-$/, ''); // Remove last -
<template>
<nav>
<ul class="pagination">
<li v-if="pagination.current_page > 1">
<a href="javascript:void(0)" aria-label="Previous" v-on:click.prevent="changePage(pagination.current_page - 1)">
<span aria-hidden="true">«</span>
</a>
</li>
<li v-for="page in pagesNumber" :class="{'active': page == pagination.current_page}">
<a href="javascript:void(0)" v-on:click.prevent="changePage(page)">{{ page }}</a>
@paulund
paulund / example-wp-list-table.php
Last active March 31, 2024 05:40
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@paulund
paulund / javascript-htmlentities.js
Created October 7, 2013 12:30
Apply PHP htmlentities in JS.
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}