Skip to content

Instantly share code, notes, and snippets.

Sam Sargent samsargent

  • Vivo Group
  • Brisbane, Australia
Block or report user

Report or block samsargent

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .bash_profile
_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 "\[" ;
@samsargent
samsargent / Tar GZ - Exclude directory
Created Jul 10, 2016
Tar GZ - Exclude directory - good for copying down a live WP install and ignoring uploads
View Tar GZ - Exclude directory
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 / Reset Permissions 755 644
Created Jul 10, 2016
Reset Permissions Folders 755 Files 644
View Reset Permissions 755 644
find . -type d -exec chmod 0755 {} \; && find . -type f -exec chmod 0644 {} \;
@samsargent
samsargent / Responsinator.js
Last active Jun 1, 2016
Bookmarklet - simply show the view-port width to make it easy to see what media-query is being used.
View Responsinator.js
/* 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 / bash.sh
Created Mar 7, 2016
Bulk update to utf8/utf8_general_ci database + tables
View bash.sh
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"
View OrdinalSuffix.php
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 / archive.php
Created May 1, 2013
Wordpress: Draft Coming Soon Teasers on archive pages
View archive.php
<?php
if ( is_tax('platform')) {
$args = array(
'post_type' => 'post',
'post_status' => 'draft',
'tax_query' => array(
array(
'taxonomy' => 'platform',
'field' => 'slug',
@samsargent
samsargent / gist:5464513
Last active Dec 16, 2015
Wordpress: Change default from name & email filters
View gist:5464513
<?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 / gist:5429552
Last active Dec 16, 2015
PHP: SlimPHP PDO database connection
View gist:5429552
<?php
function getConnection() {
$dbhost="127.0.0.1";
switch(ENV){
case 'dev':
$dbuser="username";
$dbpass="password";
$dbname="databasename";
@samsargent
samsargent / latest-tweets.js
Created Apr 15, 2013
Grab latest tweets from Twitter API
View latest-tweets.js
/*
Latest Tweets Plugin
Markup required:
<div class="latestTweets" data-user="unitseven" data-count="3"></div>
*/
(function( $ ) {
"use strict";
function relative_time(time_value) {
You can’t perform that action at this time.