Skip to content

Instantly share code, notes, and snippets.

View robinnorth's full-sized avatar
:octocat:

Robin North robinnorth

:octocat:
View GitHub Profile
@robinnorth
robinnorth / git_bulk-delete-remote-tags.sh
Last active December 16, 2015 05:28 — forked from technogoat/gist:1528381
Git: Bulk delete remote tags
$ git ls-remote --tags origin | awk '/^(.*)(\s+)(.*[a-z])$/ {print ":" $2}' | xargs git push origin
@robinnorth
robinnorth / git_bulk-delete-local-tags.sh
Created April 14, 2013 21:49
Git: Bulk delete local tags
$ git tag | awk '/^(.*\w)$/ {print $1}' | xargs git tag -d
@robinnorth
robinnorth / wordpress_prepare-database-for-production.sql
Created April 15, 2013 08:22
WordPress: Prepare database for production environment
# Update options
UPDATE wp_options SET option_value = REPLACE( option_value, 'staging.com', 'production.com' );
# UPDATE wp_options SET option_value = REPLACE( option_value, 'admin@staging.com', 'admin@production.com' );
# Update inline images
UPDATE wp_posts SET post_content = REPLACE( post_content, 'staging.com', 'production.com' );
# Update image attachment GUID
UPDATE wp_posts SET guid = REPLACE( guid, 'staging.com', 'production.com' ) WHERE post_type = 'attachment';
@robinnorth
robinnorth / wordpress_delete-post-revisions.sql
Created April 15, 2013 08:23
WordPress: Delete post revisions
DELETE a, b, c
FROM wp_posts a
LEFT JOIN wp_term_relationships b
ON a.ID = b.object_id
LEFT JOIN wp_postmeta c
ON a.ID = c.post_id
WHERE a.post_type = 'revision';
@robinnorth
robinnorth / bash_cheat-sheet.sh
Created April 15, 2013 08:25
Bash: Cheat sheet
# chmod all files in directory, including .hidden files
chmod [MODE] .[a-zA-Z0-9_]*
# create gzipped tarball, preserving permissions
tar -c -p -v -z -f /home/example/www.example.com_site-2013-04-15.tar.gz -C /home/example/ .
# Recursively chmod only directories
find . -type d -exec chmod 755 {} \;
# Similarly, recursively set the execute bit on every directory
@robinnorth
robinnorth / wordpress_export-post-data.php
Created April 26, 2013 11:44
WordPress: Simple, configurable script to export post data to a CSV file
<?php
/**
* Export WordPress post data to CSV
* Based on <http://stackoverflow.com/a/3474698> and <http://ran.ge/2009/10/27/howto-create-stream-csv-php/>
*/
/**
*********************************************************************
* Configuration
*********************************************************************
@robinnorth
robinnorth / bash_wget-mirror-website.sh
Created May 17, 2013 15:32
Bash: Create a static mirror of a website using wget
$ wget --mirror --no-parent --adjust-extension --restrict-file-names=windows --convert-links --page-requisites --verbose --directory-prefix=/home/user/path http://www.example.com/
@robinnorth
robinnorth / git_remove-ignored-files.sh
Last active February 21, 2018 16:24
Git: Remove all files ignored by .gitignore from repository
git rm -r --cached .
git add .
git commit -m 'Removed all files that are in the .gitignore'
@robinnorth
robinnorth / node_chown-global-modules.sh
Created May 15, 2014 08:01
Changes ownership of global `node_modules` directory to current user on OS X
sudo chown -R `whoami` /usr/local/lib/node_modules
DB="your_database_name"
USER="your_db_user"
PASS="your_db_pass"
HOST="database_hostname"
(
echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'
mysql -p $PASS -u $USER -h $HOST "$DB" -e "SHOW TABLES" --batch --skip-column-names \
| xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'
) \
| mysql -p $PASS -u $USER -h $HOST "$DB"