Skip to content

Instantly share code, notes, and snippets.

@scottlee
scottlee / reload-browser.scpt
Last active March 7, 2024 19:25
Applescript for reloading a browser in the background. Useful when paired up with an Automator application and PhpStorm external tool shortcut.
# Choose your browser:
# Chrome
# tell application "Google Chrome"
# reload active tab of (get window 1)
# end tell
#
# # Safari
# tell application "Safari"
# tell window 1
@scottlee
scottlee / mamp3.x-and-object-caching.md
Last active March 15, 2019 15:22
Getting object caching working with MAMP, Memcached, and WordPress

MAMP 3.x

Steps

  1. Install Brew
  2. brew install memcached
  3. brew install libmemcached
  4. Grab a memcached.so file from here. Like this one for PHP 7.0.0.
  5. Move the memcached.so file to: /Applications/MAMP/bin/php/php7.x.x/lib/php/extensions/no-debug-non-zts-200xxxxx
  6. Add the following to the end of the php.ini: extension=memcached.so
@scottlee
scottlee / Get external IP, write to file
Created August 12, 2011 20:31
Get external IP address and write to file if it has changed
#!/bin/bash
# Where should this file be stored?
ipfile=~/Desktop/external-ip.txt
# Go ahead now, go ahead and get that IP
IP=$(curl -s http://icanhazip.com)
# Has the address changed? If it has go ahead and write that bad boy down. If not, no worries.
OLDIP=""
@scottlee
scottlee / slackspotify.sh
Last active October 17, 2018 20:11 — forked from jgamblin/slackspotify.sh
A Script To Set Current Spotify Song As Slack Status - MacOS
#!/bin/bash
APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens"
trap onexit INT
function reset() {
echo 'Resetting status'
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22%22%2C%22status_emoji%22%3A%22%22%7D" > /dev/null
}
@scottlee
scottlee / wp-cli-commands.md
Last active January 15, 2016 01:50
A list of common WP-CLI commands.

Export/Import db

wp db export nameoffile.sql wp db import nameoffile.sql

Export WXR

wp export --dir=../wxr-exports --url=example.com wp export --dir=~/wxr-exports --url=example.com --start_date=2015-08-01 --end_date=2015-09-18

Using Bash

for f in ~/path-to-xmls/*.xml; do wp import $f --url=example.com --authors=create; done

#!/bin/bash
# Get IP address from output file in Dropbox.
ip=`cat ~/Dropbox/HomeNetworkIP.txt`
# Establish SSH session
ssh $ip
# To connect:
# ./Dropbox/scripts/connect_to_home.sh
@scottlee
scottlee / array-push-assoc.php
Last active December 22, 2015 04:18
Push items onto a multidimensional array.
<?php
/**
* Add items to multidimensional array
*/
function array_push_assoc( $array, $key, $value ){
$array[$key] = $value;
return $array;
}
@scottlee
scottlee / menus.php
Created June 4, 2013 18:56
If the current page has child menu items, display them. Hazzah!
<?php
/**
* Returns the submenu items of the parent menu item.
* @param $sorted_menu_items
* @param $args
* @return mixed
*/
function theme_wp_nav_menu_sub_menu_objects( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
@scottlee
scottlee / header.php
Created May 15, 2013 19:52
Add favicon to WordPress
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
@scottlee
scottlee / gist:5584524
Created May 15, 2013 14:46
All external links in new window.
<script>
$(document).ready(function() {
$('a[href]')
.filter(function(){
return ($(this).attr('href').match(new RegExp('^https?|ftp')));
})
.filter(function(){
return (! $(this).attr('href').match(new RegExp('^(https?|ftp):\/\/'+location.hostname)));
})
.attr('target', '_blank');