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
name: matching
on:
push:
paths:
- "backend/matching/**"
- ".github/workflows/matching.yaml"
pull_request:
jobs:
@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
@jrmadsen67
jrmadsen67 / gist:605c29e17822e53ebf94
Created July 5, 2014 23:22
Decouple Twitter Bootstrap from your html
"Just make it with Boostrap & we'll put something better behind it later"
How many times have you heard that? Then "later" - if it comes - means going through all of your layouts and views and changing all class names. Of course it's possible that your designer will reuse css framework class names for you, but unlikely and not at all if they are just switching to a different css framework. What to do?
My thought is - aliasing. I've always felt (as have others, I've seen) that css frameworks really "do things wrong" in how they force you to tightly couple your elements to their framework. It really defeats the purpose of a separate stylesheet to begin with. So, playing around a little I came up with this experiment. I'm not a designer first - my focus is on the backend stuff - so I'd really appreciate any feedback on the idea. Is this actually practicable? Does it stir the juices and give you a better idea? Please let me know!
------
I'm using Sass, but I'm sure you can do something similar with LESS.
@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: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: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()
{