Skip to content

Instantly share code, notes, and snippets.

View mandiwise's full-sized avatar

Mandi Wise mandiwise

  • Edmonton, Canada
View GitHub Profile
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:16
Auto-populate page title of previously-viewed page in a Gravity Form field
<?php
function awi_autopopulate_workshop_title( $value ){
$referer_id = url_to_postid( wp_get_referer() );
$workshop_title = get_the_title( $referer_id );
return $workshop_title;
}
add_filter( 'gform_field_value_workshop_title', 'awi_autopopulate_workshop_title' );
// Usage:
// Add code to functions.php or similar
@mandiwise
mandiwise / Count lines in Git repo
Last active April 19, 2024 02:22
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@mandiwise
mandiwise / Stop tracking directory in Git repo
Last active April 11, 2023 16:28
A command to stop tracking and entire directory in a Git repo
// Reference: http://stackoverflow.com/questions/936249/stop-tracking-and-ignore-changes-to-a-file-in-git
$ git rm --cached -r <dir>
@mandiwise
mandiwise / Update remote repo
Last active April 17, 2024 07:41
Transfer repo from Bitbucket to Github
// Reference: http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/
// See also: http://www.paulund.co.uk/change-url-of-git-repository
$ cd $HOME/Code/repo-directory
$ git remote rename origin bitbucket
$ git remote add origin https://github.com/mandiwise/awesome-new-repo.git
$ git push origin master
$ git remote rm bitbucket
@mandiwise
mandiwise / highlighting.bash
Created October 9, 2015 17:36
Use Highlight to copy and paste code with syntax highlight.
pbpaste | highlight -S css -O rtf --style moria | pbcopy
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:18
Custom WP excerpts (with allowed HTML tags and custom read more link)
<?php
/**
* Customize excerpt length and style.
*
* @param string The raw post content.
* @return string
*/
function red_wp_trim_excerpt( $text ) {
$raw_excerpt = $text;
@mandiwise
mandiwise / functions.php
Last active November 30, 2015 04:15
Customize archive title in WP
<?php
/**
* Customize the Product archive title
*/
function red_archive_title( $title ) {
if ( is_post_type_archive( 'product' ) ) {
$title = 'Our Products Are Made Fresh Daily';
} elseif ( is_tax( 'product-type' ) ) {
$title = sprintf( '%1$s', single_term_title( '', false ) );
} elseif ( is_post_type_archive( 'testimonial' ) ) {
@mandiwise
mandiwise / hide-default-posts.php
Last active November 30, 2015 04:03
Hide post-related screens in the WordPress admin area, including Categories and Tags.
<?php
/**
* Plugin Name: Hide Default Posts
* Plugin URI: https://gist.github.com/mandiwise/2ea571ae0773b340af5a
* Description: Hide post-related screens in the WP admin area, including Categories and Tags.
* Version: 1.0.0
* Author: Mandi Wise
* Author URI: http://mandiwise.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@mandiwise
mandiwise / nav.js
Last active November 30, 2015 18:01
A simple nav-bar locking jQuery script.
/**
* Navbar Locking
*/
$(function () {
var $window = $(window),
$mainNav = $('.main-navigation'), // nav wrapper element
stickyNavTop = $mainNav.offset().top;
@mandiwise
mandiwise / .bash_profile
Created February 19, 2016 19:44
Customize bash prompt with highlighted git branch
txtcyn=$'\e[0;36m' # Cyan
txtred=$'\e[0;31m' # Red
txtwht=$'\e[0;37m' # White
txtrst=$'\e[0m' # Text Reset
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[$txtcyn\]\$(parse_git_branch) \[$txtrst\]\$ " # fancify Terminal prompt