Skip to content

Instantly share code, notes, and snippets.

View samsargent's full-sized avatar

Sam Sargent samsargent

View GitHub Profile
@samsargent
samsargent / gist:5429552
Last active December 16, 2015 11:48
PHP: SlimPHP PDO database connection
<?php
function getConnection() {
$dbhost="127.0.0.1";
switch(ENV){
case 'dev':
$dbuser="username";
$dbpass="password";
$dbname="databasename";
@samsargent
samsargent / gist:5464513
Last active December 16, 2015 16:39
Wordpress: Change default from name & email filters
<?php
function my_wp_mail_from_name($name) {
return 'From Name';
}
//email from email function
function my_wp_mail_from($content_type) {
return 'from@emailaddress.com.au';
}
add_filter('wp_mail_from','my_wp_mail_from');
add_filter('wp_mail_from_name','my_wp_mail_from_name');
@samsargent
samsargent / archive.php
Created May 1, 2013 00:28
Wordpress: Draft Coming Soon Teasers on archive pages
<?php
if ( is_tax('platform')) {
$args = array(
'post_type' => 'post',
'post_status' => 'draft',
'tax_query' => array(
array(
'taxonomy' => 'platform',
'field' => 'slug',
function ordinal($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if ((($number % 100) >= 11) && (($number%100) <= 13))
return $number. 'th';
else
return $number. $ends[$number % 10];
}
@samsargent
samsargent / bash.sh
Created March 7, 2016 04:54
Bulk update to utf8/utf8_general_ci database + tables
DB="DBNAME"; ( echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'; mysql -u root "$DB" -e "SHOW TABLES" --batch --skip-column-names | xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' ) | mysql -u root "$DB"
@samsargent
samsargent / Responsinator.js
Last active June 1, 2016 12:55
Bookmarklet - simply show the view-port width to make it easy to see what media-query is being used.
/* Responsinator Bookmarklet - simply show the viewport width to make it easy to see what media-query is being applied.
*/
(function(){
var el=document.createElement('div');
el.style.position='fixed';
el.style.height='50';
el.style.width='300';
el.style.margin='-25px -150px 0 0';
el.id='unitseven-size';
el.style.top='50%';
@samsargent
samsargent / Reset Permissions 755 644
Created July 10, 2016 22:11
Reset Permissions Folders 755 Files 644
find . -type d -exec chmod 0755 {} \; && find . -type f -exec chmod 0644 {} \;
@samsargent
samsargent / Tar GZ - Exclude directory
Created July 10, 2016 22:14
Tar GZ - Exclude directory - good for copying down a live WP install and ignoring uploads
tar -czvf filename.tar.gz /full/path/to/directory --exclude "/full/path/to/directory/to/exclude/wp-content/uploads"
Use this on local /wp-content/uploads:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://domain.com/wp-content/uploads/$1
</IfModule>
@samsargent
samsargent / .bash_profile
Created January 24, 2017 02:20
SSH Autocomplete
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
$('a[href$=".pdf"]').click(function(){
ga('send', {
hitType: 'event',
eventCategory: 'Download',
eventAction: 'PDF',
eventLabel: this.href
});
});