Skip to content

Instantly share code, notes, and snippets.

View daltonrooney's full-sized avatar

Dalton Rooney daltonrooney

View GitHub Profile
@daltonrooney
daltonrooney / modal-video.vue
Last active April 26, 2024 08:41
Modal video player component for Vue.js
/* Based on https://github.com/appleple/react-modal-video/ */
<template>
<div v-if="isOpen">
<div
:class="classNames.modalVideo"
tabIndex='-1'
role='dialog'
:aria-label="aria.openMessage"
@click="$emit('update:isOpen', false)"
@daltonrooney
daltonrooney / mssql_to_csv.bash
Created February 20, 2024 23:17 — forked from llimllib/mssql_to_csv.bash
This is a script to convert every table in a Microsoft SQL Server database backup (.bak file) to a .csv file
#!/usr/bin/env bash
# import an MS SQL .bak backup file to an MS SQL database, then export all
# tables to csv. run this script as `import.sh <filename>`. It expects to be
# run in the same directory as the backup file.
# this is only tested on my mac (OS X Catalina). I tried to stick to posix, but
# It will probably require some tweaking for you. I hope it gives a general
# sense of what you need to do at the very least.
@daltonrooney
daltonrooney / gist:2570640
Created May 1, 2012 19:16
PSP 1.6.1 custom js
/*!
* jQuery imagesLoaded plugin v2.0.1
* http://github.com/desandro/imagesloaded
*
* MIT License. by Paul Irish et al.
*/
(function(a,b){var c="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";a.fn.imagesLoaded=function(k){var h=this,m=a.isFunction(a.Deferred)?a.Deferred():0,l=a.isFunction(m.notify),e=h.find("img").add(h.filter("img")),f=[],j=[],g=[];function i(){var n=a(j),o=a(g);if(m){if(g.length){m.reject(e,n,o)}else{m.resolve(e)}}if(a.isFunction(k)){k.call(h,e,n,o)
}}function d(n,o){if(n.src===c||a.inArray(n,f)!==-1){return}f.push(n);if(o){g.push(n)}else{j.push(n)}a.data(n,"imagesLoaded",{isBroken:o,src:n.src});if(l){m.notifyWith(a(n),[o,e,a(j),a(g)])}if(e.length===f.length){setTimeout(i);e.unbind(".imagesLoaded")}}if(!e.length){i()}else{e.bind("load.imagesLoaded error.imagesLoaded",function(n){d(n.target,n.type==="error")}).each(function(n,p){var q=p.src;var o=a.data(p,"imagesLoaded");if(o&&o.src===q){d(p,o.isBroken);return}if(p.complete&&p.naturalWidth!==b){d(p,p.naturalWidt
@daltonrooney
daltonrooney / get_stores_by_location.php
Last active June 29, 2023 14:14
Store locator with Advanced Custom Fields
<?php
function mbn_get_stores_by_location( $zip, $radius ) {
global $wpdb;
$radius = intval( $radius );
// we first need to get the source coordinates
$sql = "SELECT `latitude`, `longitude` FROM `wp_zip_codes` WHERE `zipcode` = '%s'";
$coords = $wpdb->get_row( $wpdb->prepare( $sql, $zip ) );
@daltonrooney
daltonrooney / contentModule.gql
Last active May 15, 2023 23:24
Craft CMS GraphQL matrix shared fragment example
import gql from 'graphql-tag'
import { print } from 'graphql/language/printer'
import richTextFragment from './contentModules/richText.gql'
import logoBlockFragment from './contentModules/logoBlock.gql'
import embedBlockFragment from './contentModules/embedBlock.gql'
import videoBlockFragment from './contentModules/videoBlock.gql'
import imageCollageFragment from './contentModules/imageCollage.gql'
import imageGridFragment from './contentModules/imageGrid.gql'
import slideshowBlockFragment from './contentModules/slideshowBlock.gql'
import singleImageFragment from './contentModules/singleImage.gql'
@daltonrooney
daltonrooney / app.js
Last active October 14, 2022 16:35
Craft CMS GQL query w/ filters and pagination
import Vue from 'vue'
import { debounce } from './utils/debounce';
import { ProCatalogCategoriesQuery } from './queries/proCatalogCategories.gql';
import { makeProCatalogResourcesQuery } from './queries/proCatalogResources';
import Loading from './components/loading.vue';
const GraphqlEndpoint = '/api'
const ResultsPerPage = 12;
const el = document.querySelector('#professional-catalog-app')
@daltonrooney
daltonrooney / module.php
Created May 12, 2020 22:32
Clear Craft CMS cache after Entry save event
<?php
use yii\base\Event;
use Craft;
use craft\elements\Entry;
Event::on(
Entry::class,
Entry::EVENT_AFTER_SAVE,
function(ModelEvent $event) {
@daltonrooney
daltonrooney / file-upload-handler.php
Created February 4, 2012 13:29
Multi-file WordPress uploads from the front-end
<?php /* This function attaches the image to the post in the database, add it to functions.php */
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
// Hover.com "Zone file import/export" has been *Planned* since 2011
// https://help.hover.com/entries/471066-Zone-file-import-export
// Here's a brittle approximation of export.
//
// 1. login to your account: https://www.hover.com/domains
// 2. run the following in your browser's JavaScript console, changing the first line
// to your domain
// 3. copy the text logged to the console.
// 4. manually correct FQDNs, these have to end with a period "."
//
@daltonrooney
daltonrooney / paypal_sub_exclude_woocom.php
Last active November 11, 2021 08:34
Exclude PayPal gateway for WooCommerce subscriptions
/* $productCategoryID includes all subscription products */
function cart_includes_subscription_category() {
$productCategoryID = 10;
global $woocommerce;
$product_in_cart = false;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) :
$_product = $values['data'];
$terms = get_the_terms( $_product->id, 'product_cat' );
if ( $terms ) :
foreach ($terms as $term) :