Skip to content

Instantly share code, notes, and snippets.

View tomfordweb's full-sized avatar
🏠
Working from home

Tom Ford tomfordweb

🏠
Working from home
View GitHub Profile
// Usage
// input = buildHTML('input', {
// type: 'hidden',
// value: response.csrf_token,
// name : '_token'
// })
buildHTML = function(tag, html, attrs) {
// you can skip html param
if (typeof(html) != 'string') {
@tomfordweb
tomfordweb / ValidatesEmailTrait.php
Last active April 4, 2017 18:40
Mailgun Email Validation for Laravel 5
<?php namespace App\Http;
// composer require mailgun/mailgun-php php-http/curl-client guzzlehttp/psr7
use Mailgun\Mailgun;
trait ValidatesEmailTrait {
/**
* Validates an email against Mailguns validation API, this is to reduce spam and nefarious login attempts.
@tomfordweb
tomfordweb / RecaptchaTrait.php
Created April 4, 2017 18:40
Laravel Recaptcha Trait
<?php namespace App\Http;
/**
* Need to create goog recaptcha data before usage
*/
use Request;
trait RecaptchaTrait {
public function validateCaptchaString($secret, $response_string, $remote_ip)
@tomfordweb
tomfordweb / collection-to-csv.php
Last active April 10, 2017 14:17
L5 Collection to CSV String for import
<?php
/**
* Generates a comma delimited by column with newline character for rows of models.
* If needed to be used on a actual model and not fake data, just pass the methods following the factory to the collection.
*/
$model = Model::class;
$quantity = 2;
@tomfordweb
tomfordweb / Searchable.php
Created April 10, 2017 14:40
L5 Searchable Trait
<?php namespace App;
trait Searchable {
/**
* Search for a model based off of the "fillable" property of the model
* @param type $query The query, no need to insert this into method as L typehints it
* @param string $term The search term
* @return type The modified query
*/
@tomfordweb
tomfordweb / URLSafeHash.php
Created April 10, 2017 19:52
URL Safe Hash Methods
<?php
/**
* Generate a hashed string that is URL save
* @param string $string The string to hash
* @return string Hashed string
*/
function urlSafeHashMake($string)
{
return strtr(base64_encode($string), '+/=', '-_,');
@tomfordweb
tomfordweb / wp-single-level-nav.php
Created June 1, 2017 15:59
WP Single Level Menu Helper
<?php
class SingleLevelNav
{
public $location;
function __construct($location)
{
$this->location = $location;
add_filter( 'wp_nav_menu_args', [$this, 'forceSingleLevelNav'], 10);
@tomfordweb
tomfordweb / index.js
Created June 7, 2017 15:34
JQuery + Bootstrap 3 - Responsive Breakpoint body classes
function addResponsivePixelToBody()
{
$('body').append('<div id="xs-res" class="hidden-sm hidden-md hidden-lg"></div><div id="small-res" class="hidden-md hidden-xs hidden-lg"></div><div id="medium-res" class="hidden-sm hidden-xs hidden-lg"></div><div id="large-res" class="hidden-sm hidden-xs hidden-md"></div><div class="col-sm-12 col-md-4 text-center">');
}
function responsiveBreakpoints()
{
var xs = $('#xs-res');
var small = $('#small-res');
var med = $('#medium-res');
var large = $('#large-res');
@tomfordweb
tomfordweb / csc.php
Last active July 17, 2017 13:24
User Defined Shortcodes in WP, uses ACF repeater and options plugin, but can be configured to run on anything
<?php
/**
* Adds "user defined" shortcodes via ACF options and repeater plugins
*/
function addUserDefinedShortCodes()
{
if( have_rows('codes','option') ):
// loop through the rows of data
@tomfordweb
tomfordweb / SPEAK-MURICAN.sql
Last active December 14, 2017 23:28
Replace non-english characters. Back up your database and make sure you want to use every query here.
# Good for fixin urls
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'.',' ');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,' ','-');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'--','-');
UPDATE TABLE_NAME SET COLUMN = LOWER(COLUMN);
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Š','S');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'š','s');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ð','Dj');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ž','Z');