Skip to content

Instantly share code, notes, and snippets.

Avatar

Pat Gilmour patrickgilmour

  • Self-employed
  • Brookyln, New York, USA
View GitHub Profile
@patrickgilmour
patrickgilmour / dayone-import-from-ulysses-text-file.scpt
Last active Nov 6, 2021
AppleScript to import Ulysses text files to DayOne
View dayone-import-from-ulysses-text-file.scpt
--Script to import text files (Markdown)
--exported from External folder in Ulysses (Mac)
--to a Finder folder THE_FOLDER
--Imports entries from that folder with tags (Keywords) and removes tags
--from body of the entry
--Entry date is same as Creation Date of text file
--Required DayOne CLI tool installed on Mac
tell application "Finder"
@patrickgilmour
patrickgilmour / truncate-string-to-word.php
Created Oct 13, 2015
Truncates a string to the nearest defined word boundary.
View truncate-string-to-word.php
<?php
// Truncates a string to 275 characters to the nearest word
// from: preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, 201));
$the_substring = preg_replace('/\s+?(\S+)?$/', '', substr( $the_string , 0, 275));
@patrickgilmour
patrickgilmour / Rewrite-to-HTTPS-for-MAMP
Last active Oct 12, 2015
MAMP - Force Host to use https for all pages using rewrites in MAMP
View Rewrite-to-HTTPS-for-MAMP
# Paste the following into the Additional Parameters for <Virtual Host> field of the "Hosts" tab in MAMP (Pro)
# Restart MAMP
# Now when you type http://thishost MAMP with forward the request to https://thishost
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
@patrickgilmour
patrickgilmour / gravity-forms-scroll-jump.php
Last active Aug 30, 2015
On submitting a Gravity Form (with id of 25), the response page will jump to top of the page minus 1 px
View gravity-forms-scroll-jump.php
/**
* Gravity Forms - scroll to the top of page on form submit
*
* Returns a value of 1px from the top.
*/
add_filter( 'gform_confirmation_anchor_25', function() {
return 1;
} );
View option_page_capability.php
<?php
/**
* Allow users with capability 'my_edit_settings' to edit the `my_plugin_options` settings of your Plugin
*
* This avoids giving them 'manage_options' capabilities
*
* @category WordPress
* @see https://codex.wordpress.org/Function_Reference/add_options_page
*
View wc-remove-all-stylesheets.php
/**
* WooCommerce enqueues 3 stylesheets by default. You can disable them all using:
*
* see http://docs.woothemes.com/document/disable-the-default-stylesheet/
*/
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
@patrickgilmour
patrickgilmour / google_analytics_exclude_local.js
Created Jul 7, 2014
Google Analytics - only track live/production site hits and don't send hits from localhost or other development domains.
View google_analytics_exclude_local.js
<script>
// Replace MYLIVEDOMAIN.com with your domain.
// Google Analytics will now not receive hits from cloned development versions of your site on localhost etc.
// Also checkout `Block Yourself from Analytics` plugin for Chrome
// see also: http://stackoverflow.com/questions/1251922/is-there-a-way-to-stop-google-analytics-counting-development-work-as-hits
if (document.location.hostname.search("MYLIVEDOMAIN.com") !== -1) {
/* Google Analytics Code here */
@patrickgilmour
patrickgilmour / wp-get-image-alt-text.php
Created Jun 28, 2014
WordPress Images - echo the Alt text of the Featured image (and other image attributes)
View wp-get-image-alt-text.php
<?php
/**
* Get the Alt text of a Featured Image
*
* And other image attributes
*/
add_action('genesis_before_sidebar_widget_area', 'pgwp_genesis_before_sidebar_widget_area' );
function pgwp_genesis_before_sidebar_widget_area () {
@patrickgilmour
patrickgilmour / woocommerce-filter-single-product-page-title.php
Created Jun 27, 2014
Filter the Title of a WooCommerce Product on the Single Product Page
View woocommerce-filter-single-product-page-title.php
<?php
/**
* Rename/Filter the Title of a WooCommerce Product on the Single Product Page
*
*/
add_filter('the_title', 'xcsn_single_product_page_title', 10, 2);
function xcsn_single_product_page_title($title, $id) {
if( ( is_product() && in_the_loop() ) ) {
@patrickgilmour
patrickgilmour / woocommerce-simple-or-variable.php
Created Jun 27, 2014
WooCommerce conditional to test if a Product is Simple or Variable.
View woocommerce-simple-or-variable.php
<?php
/**
* Is a WooCommerce Product Simple or Variable
*
* see http://wordpress.org/support/topic/condition-to-check-if-product-is-simple-or-variable
*/
if( $product->is_type( 'simple' ) ){
// a simple product