Skip to content

Instantly share code, notes, and snippets.

View jrmadsen67's full-sized avatar
💭
Looking for new remote opportunities

Jeff Madsen jrmadsen67

💭
Looking for new remote opportunities
View GitHub Profile
@jrmadsen67
jrmadsen67 / gist:bd0f9ad0ef1ed6bb594e
Last active August 19, 2024 10:37
Laravel Quick Tip: Handling CsrfToken Expiration gracefully
Quick tip for handling CSRF Token Expiration - common issue is when you use csrf protection is that if
a form sits there for a while (like a login form, but any the same) the csrf token in the form will
expire & throw a strange error.
Handling it is simple, and is a good lesson for dealing with other types of errors in a custom manner.
In Middleware you will see a file VerifyCsrfToken.php and be tempted to handle things there. DON'T!
Instead, look at your app/Exceptions/Handler.php, at the render($request, Exception $e) function.
All of your exceptions go through here, unless you have excluded them in the $dontReport array at the
name: matching
on:
push:
paths:
- "backend/matching/**"
- ".github/workflows/matching.yaml"
pull_request:
jobs:
@jrmadsen67
jrmadsen67 / gist:5815505
Last active May 1, 2017 21:32
Next time someone asks you to take a FizzBuzz Test...
$biggest =100;
$all_numbers = range(0,$biggest);
$threes = array_fill_keys(range(3, $biggest, 3), 'Fizz');
$fives = array_fill_keys(range(5, $biggest, 5), 'Buzz');
$fifteens = array_fill_keys(range(15, $biggest, 15), 'FizzBuzz');
$all_numbers = array_replace($all_numbers, $threes, $fives, $fifteens);
var_dump($all_numbers);
@jrmadsen67
jrmadsen67 / gist:6349826
Created August 27, 2013 05:12
MY_text_helper - very quick & dirty version of the character_limiter() that allows you to set a hard limit on the length and it will roll back the last word
<?php
/**
* Character Limiter
*
* Limits the string based on the character count. Preserves complete words
* so the character count may not be exactly as specified.
*
* @access public
* @param string
@jrmadsen67
jrmadsen67 / gist:6255706
Created August 17, 2013 07:22
Takes a string of numbers that may include , or - ranges & parses it into array Ex: chapters can be "1,3-6, 8-10" and will make an array of array(1,3,4,5,6,8,9,10);
public function parse_list($chapters)
{
//just a single number passed
if (is_numeric($chapters)) return array((int)$chapters);
$chapter_array = array();
//break up based on ,
@jrmadsen67
jrmadsen67 / gist:5105520
Created March 7, 2013 04:11
Get occurrences of a particular month, when using Unix timestamps in your db php construction of sql, but recreate as needed. $month & $year are integers
WHERE MONTH(FROM_UNIXTIME(cdate)) = '.$month.' AND YEAR(FROM_UNIXTIME(cdate)) = '. $year;
@jrmadsen67
jrmadsen67 / gist:5097167
Created March 6, 2013 06:25
Get preceding 12 month array, starting with 12 months earlier and ending in current month (ex. Today is Mar, so array will be Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Jan,Feb,Mar)
$date = new DateTime((date('Y')-1).'-'.date('m').'-01' ); //to kill the 31 day problem
$months_array = array_map(function($val) use ($date) {return $date->add(new DateInterval('P1M'))->format('M');}, range(1,12));
@jrmadsen67
jrmadsen67 / gist:5028002
Last active December 14, 2015 04:28
Takes data from a key:value table & combines it onto a single-row record, per item
/*
Data starts in table:
ProjectId, key, value
1 totaltime 02:34:56
1 zip.url http://www.mysite.com/download/file.zip
1 zip.size 12MB
@jrmadsen67
jrmadsen67 / gist:4695757
Created February 2, 2013 02:18
Playing around with callbacks in array_map. Notice array($this, 'process') lets you specify an object->method, perfect for use in framework controller (like in Codeigniter)
<?php
$main_object = new main_object();
$main_object->main();
class main_object{
function main()
{
@jrmadsen67
jrmadsen67 / gist:4618291
Last active December 11, 2015 14:59
jquery function to move focus to next element of group when max length hit. for use with phone numbers, dates, etc
// assumes you set tabIndex="0" ... last element in group
// set all elements in group with same class
// set each element with max length
// obviously, "phones" is not generic, easy to switch. Code I just wrote for something quick; will fix that later
$('.phone').keyup(function(){
jumpNext($(this), $(this).val())
});