Skip to content

Instantly share code, notes, and snippets.

View brettkelly's full-sized avatar

Brett Kelly brettkelly

View GitHub Profile
@brettkelly
brettkelly / InstallSendPdfToEvernote
Created February 15, 2012 18:19
Install the "Send PDF to Evernote" option in the Print > PDF menu
tell application "Finder"
try
set appPath to (path to application "Evernote" as text)
on error
display dialog "Couldn't find Evernote. Is it installed?"
end try
set printPath to (path to "dlib" from user domain as text) & "PDF Services"
make new alias at printPath to appPath with properties {name:"Send PDF to Evernote"}
end tell
@brettkelly
brettkelly / makeAmazonAffUrl.py
Created July 15, 2012 04:29
Python to rework Amazon URL to contain the user's affiliate code
#!/usr/bin/env python
# (c) 2012 Brett Kelly.
# Licensed under the MIT license
# http://www.opensource.org/licenses/mit-license.php
import re
import sys
from urlparse import urlparse
@brettkelly
brettkelly / oauth_example.py
Created February 26, 2013 18:55
Authenticate with the Evernote Cloud API using OAuth and Python
# Python OAuth example
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
##
# Helper function to turn query string parameters into a
# Python dictionary
##
@brettkelly
brettkelly / functions.php
Created February 15, 2023 19:44
Hide an HTML element by class based on WP user role
<?php
// Hide the Inventory nav item for everybody except admins and buyers
function rw_hide_inventory_link_for_role() {
$allowed_roles = ['administrator', 'rw-buyer']; // these user roles can see the item
$hide = true; // default to hiding it
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = (array)$user->roles;
foreach($roles as $role) {
@brettkelly
brettkelly / functions.php
Created January 5, 2023 04:27
An example of a WordPress shortcode that takes parameters
<?php
/*
Collect and display a sorted, unordered list element containing all children of the current post
Supported attributes:
`remove` = this string will be removed in the resulting links
`exclude` = posts whose title contains one of these comma-separated strings will be omitted
TODO: fix both params to be pipe-delimited because flexibility
*/
@brettkelly
brettkelly / nvAltNoteFromSelection.applescript
Created April 18, 2013 18:02
AppleScript to create a new nvAlt note from the selected text in any app.
-- copy selected text
tell application "System Events"
keystroke "c" using command down
end tell
-- switch to nvAlt
tell application "nvALT"
activate
tell application "System Events"
keystroke "l" using command down -- Create or Search
@brettkelly
brettkelly / us_state_abbreviations.py
Last active July 13, 2022 21:58 — forked from JeffPaine/us_state_abbreviations.py
A python list of all US state abbreviations.
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
elements = [".some-class", "#some-id"]; // selectors for each element to suppress events
events = ["mouseover", "click"]; // events to suppress
document.addEventListener("fullscreenchange", (event) => {
// fullscreen event fired
elements.forEach((element) => {
events.forEach((event) => {
if (document.fullscreenElement) {
// some element has fullscreen now
document.querySelectorAll(element).forEach((el) => {
el.addEventListener(event, (e) => {
import React, {useState, useEffect} from "react"
import {useRouter} from 'next/router'
const Event = ({embed}) => {
const router = useRouter()
const [embedSRC, setEmbedSRC] = useState(embed);
// useEffect(() => {
// const handleRouteChange = () => {
// setEmbedSRC(embed)
// }
@brettkelly
brettkelly / epro-cpt-archive-override.php
Created January 28, 2022 21:11
Override the archive title for a CPT in Elementor Pro
<?php
// ganked this from a FB group thread that linked to a dead E doc page.
// Storing here for reference/posterity.
function archive_callback( $title ) {
// make this a switch if you want to handle a bunch of different CPTs in one go
if ( is_post_type_archive('my_cpt_slug') ) {
return 'My custom archive title, baybay';
}