Skip to content

Instantly share code, notes, and snippets.

View james2doyle's full-sized avatar

James Doyle james2doyle

View GitHub Profile
@james2doyle
james2doyle / shopify-vue-app.js
Last active September 18, 2023 10:49
Support Vue apps inside the Shopify section editor. Supports refreshing the Vue instance when changes happen in the section editor
import Vue from 'vue';
/**
* EventHub to listen or broadcast to all components
*
* @see https://shopify.dev/tutorials/develop-theme-sections-integration-with-theme-editor
*
* Usage: eventHub.$on('shopify:section:select:{my-section-name}', (event) => handleSelect());
*
*/
@james2doyle
james2doyle / curl-smtp-email.sh
Last active September 15, 2023 17:21
Send SMTP email using cURL
curl --connect-timeout 15 -v --insecure "smtp://smtp.example.com:25" -u "username:password"
\ --mail-from "sender@example.com" --mail-rcpt "destination@example.com"
\ -T email-contents.txt --ssl
@james2doyle
james2doyle / pagination.php
Last active August 26, 2023 07:52
Simple pagination element with dot separation when large counts
<div class="pagination size1of1 unit">
<?php if($paged == 1): ?>
<span class="current"><?php echo $paged ?></span>
<?php else: ?>
<a class="prev" href="?page=<?php echo ($current_page - 1) ?>">Prev</a>
<?php if ($current_page > 2): ?>
<a href="?page=1">1</a>
<?php endif ?>
<?php if ($current_page > 3): ?>
<span class="dots">...</span>
@james2doyle
james2doyle / simple templating
Created September 20, 2012 16:36
Simple Javascript Templating
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@james2doyle
james2doyle / bench.sh
Last active July 22, 2023 06:54
A website benchmarking script using Apache ab. This script hits a target with requests and then generates a small report for each case.
#!/usr/bin/env bash
# idea from https://www.devside.net/wamp-server/load-testing-apache-with-ab-apache-bench
# if you are testing a base url, you need a trailing slash
SITE="http://example.com/"
OUTFILE="output.txt"
DIVIDER="\n====================================================================\n"
# if the file doesnt exist, make it
@james2doyle
james2doyle / shopify-template-links.md
Last active July 17, 2023 10:25
A list of links to the documentation for the required templates in a Shopify theme
@james2doyle
james2doyle / jquery.getStylesheet.js
Created February 3, 2016 21:05
An implementation of $.getScript but for stylesheets. Call it $.getStylesheet
(function($) {
$.getStylesheet = function (href) {
var $d = $.Deferred();
var $link = $('<link/>', {
rel: 'stylesheet',
type: 'text/css',
href: href
}).appendTo('head');
$d.resolve($link);
return $d.promise();
@james2doyle
james2doyle / social.blade.php
Created March 17, 2016 19:39
Social Share Links in Laravel Blade syntax
<a href="https://www.facebook.com/sharer.php?u={{ $url }}" rel="me" title="Facebook" target="_blank"><i class="fa facebook"></i></a>
<a href="https://twitter.com/share?url={{ $url }}&text={{ $title }}" rel="me" title="Twitter" target="_blank"><i class="fa twitter"></i></a>
<a href="https://pinterest.com/pin/create/button/?url={{ $url }}&media={{ $image }}&description={{ $title }}" rel="me" title="Pinterest" target="_blank"><i class="fa pinterest"></i></a>
<a href="https://www.thefancy.com/fancyit?ItemURL={{ $url }}&Title={{ $title }}&Category={{ $category }}&ImageURL={{ $image }}" rel="me" title="Fancy" target="_blank"><i class="fa fancy"></i></a>
<a href="https://plus.google.com/share?url={{ $url }}" rel="me" title="Google Plus" target="_blank"><i class="fa google"></i></a>
@james2doyle
james2doyle / cache-bust-hubspot-css.js
Created May 24, 2017 17:34
Cache bust CSS files on Hubspot
// get all the link files with timestamp caches
Array.from(document.querySelectorAll('link[href*="?t="]')).forEach(el => {
// replace the href with a new one with a refreshed cache stamp
el.href = el.href.replace(/(?:t=)(\d+)/, 't=' + Date.now());
});
@james2doyle
james2doyle / search-on-kagi.sh
Created May 17, 2023 22:19
A simple Raycast script for passing your query to the Kagi FastGPT bot
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Search on Kagi
# @raycast.mode compact
# @raycast.argument1 { "type": "text", "placeholder": "query", "percentEncoded": true }
# Optional parameters:
# @raycast.icon images/icon-kagi.png