Skip to content

Instantly share code, notes, and snippets.

View joeydi's full-sized avatar

Joe di Stefano joeydi

View GitHub Profile
@joeydi
joeydi / admin.py
Created March 28, 2024 13:48
Populate inline formset initial values
class ShiftInlineForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
ordinals = [
'First',
'Second',
'Third',
'Fourth',
'Fifth',
'Sixth',
'Seventh',
<?php
/**
* Given a string containing any combination of YouTube and Vimeo video URLs in
* a variety of formats (iframe, shortened, etc), each separated by a line break,
* parse the video string and determine it's valid embeddable URL for usage in
* popular JavaScript lightbox plugins.
*
* In addition, this handler grabs both the maximize size and thumbnail versions
* of video images for your general consumption. In the case of Vimeo, you must
* have the ability to make remote calls using file_get_contents(), which may be
@joeydi
joeydi / holiday-ordering.php
Created September 27, 2022 13:54
WF_HolidayOrdering
<?php
new WF_HolidayOrdering();
class WF_HolidayOrdering
{
const MANAGER_ROLES = ['administrator'];
const HOLIDAY_ORDERING_FORM_IDS = [6, 16];
const HIDDEN_FIELD_LABELS = ['In-Store Order'];
const LOCATION_FIELD_ID = 12;
from threading import Thread
import requests ## pip install requests
import time
import smtplib
## email sending function
def email_sender(input_message, email_to, client):
''' function to send email '''
to = email_to
gmail_user = '' ## email of sender account
@joeydi
joeydi / functions.php
Created January 27, 2022 19:36
React / WordPress Integration
<?php
// The include_app function loads the React app and merges in the SEO tags and post content for indexing
// Basically a poor man's server-side rendering - if I were to do this again I'd probably use Next.JS
function include_app()
{
$index = file_get_contents(EFA::theme_path('progress-meter/app/build/index.html'));
$end_head = '</head>';
@joeydi
joeydi / exportdbs.sh
Created October 5, 2021 12:21
Export All MySQL Databases
#!/bin/bash
USER="root"
PASSWORD="root"
ExcludeDatabases="Database|information_schema|performance_schema|mysql|sys"
databases=`mysql -u$USER -p$PASWORD -e "SHOW DATABASES;" | tr -d "| " | egrep -v $ExcludeDatabases`
for db in $databases; do
echo "Dumping database: $db"
@joeydi
joeydi / cf7-input-group.less
Created December 3, 2020 00:15 — forked from cfxd/cf7-input-group.less
Bootstrap 3 input group for Contact Form 7 (only tested with 1 input field and 1 submit button)
/*
*
* Bootstrap 3 input group form for Contact Form 7
*
* In the shortcode, you must use html_id="my-id"
* or html_class="my-class" to target a specific form
*
* Actual form sample:
* <label for="your-email">Email:</label>
* [email* your-email 0/ placeholder "enter your email"]
@joeydi
joeydi / validator_json_to_html.py
Created May 8, 2020 18:01
Validator.nu JSON to HTML
#!/usr/local/bin/python3
import sys
import argparse
import html
import requests
from pprint import pprint
ICON_INFO = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M13 7.5a1 1 0 11-2 0 1 1 0 012 0zm-3 3.75a.75.75 0 01.75-.75h1.5a.75.75 0 01.75.75v4.25h.75a.75.75 0 010 1.5h-3a.75.75 0 010-1.5h.75V12h-.75a.75.75 0 01-.75-.75z"></path><path fill="currentColor" fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'
ICON_ERROR = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill="currentColor" fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'
@joeydi
joeydi / post-receive.sh
Created September 24, 2019 15:44
Craft CMS post-receive hook
#!/bin/bash
WORK_TREE="/var/www/example"
GIT_DIR="/var/repo/example.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
then
@joeydi
joeydi / installwp.sh
Created October 20, 2018 19:14
Download WordPress, Create Database, and Install - Requires WP CLI
#!/bin/bash
# Download WordPress, create database, configure, and install
if [ $1 ]
then
echo "Installing in directory $1"
mkdir $1
cd $1