Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / gist:6c88a99fb408b0c67b70
Created December 4, 2015 21:28
Show/Hide files in OS X Finder
# Show all files
defaults write com.apple.finder AppleShowAllFiles YES
# Don't show hidden files
defaults write com.apple.finder AppleShowAllFiles NO
@delputnam
delputnam / wp-bootstrap-navbar-searchform.php
Created May 9, 2013 16:10
A Bootstrap navbar-compatible search form for use with Wordpress.
<form class="navbar-search pull-right" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" class="search-query" placeholder="Search" value="" name="s" id="s">
</form>
@delputnam
delputnam / windowHistorySupported.js
Created May 10, 2013 12:01
Determine if a browser supports window.history.pushState.
function windowHistorySupported() {
// If pushState is supported, return true, else return false.
return !!(window.history && window.history.pushState);
}
@delputnam
delputnam / play_sound.sh
Last active December 17, 2015 07:48
Shell script for Mac OS X to raise volume slightly, play an MP3, and lower the volume again. I use it with Alfred's workflows to trigger the sound when I press a certain key combination. It's really just for fun.
osascript -e "set Volume 3.5"
afplay ~/Dropbox/Sounds/itssofluffy.mp3
osascript -e "set Volume 1.25"
@delputnam
delputnam / gist:5601170
Created May 17, 2013 18:55
To set a WordPress custom post type menu icon in a plugin include this in the args array when registering a custom post type.
'menu_icon' => plugins_url('images/custom-post-type-icon.png', __FILE__)
@delputnam
delputnam / functions.php
Created May 20, 2013 18:36
Get all WordPress posts of a certain type that have been published.
$query = new WP_Query( array(
'post_type' => 'event_type',
'post_status' => 'publish',
'nopaging' => true
) );
while ( $query->have_posts() ) : $query->the_post();
// Do something with the post here...
endwhile;
wp_reset_postdata();
@delputnam
delputnam / gist:6308052
Last active December 21, 2015 12:49
Get the first element of an array using php.
This resets the array's internal pointer to the first element:
reset( $array );
This does not modify the original array, but does make a copy of it, only use it for small arrays:
array_shift(array_values($array));
# Tailored for default debian host on Google Cloud Compute,
# but should work for most Ubuntu/Debian systems.
# Be sure to replace 'example.com' with your URL.
# install zip, vim and wget
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y zip vim wget
# install nodejs 0.10.xx
@delputnam
delputnam / file_check.go
Created February 23, 2016 21:01
Check for existence of file using golang
if _, err := os.Stat("/path/to/file/or/dir"); os.IsNotExist(err) {
// /path/to/file/or/dir does not exist
}
if _, err := os.Stat("/path/to/file/or/dir"); err == nil {
// /path/to/file/or/dir exists
}
sudo lsof -i
sudo netstat -lptu
sudo netstat -tulpn