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',
<input type="text" class="text" name="mobilePhone" id="mobilePhone" value="" parsley-regex-message="Please enter a valid Australian mobile phone number." parsley-regexp="^\(?(?:\+?61|0)4\)?(?:[ -]?[0-9]){2}\)?(?:[ -]?[0-9]){5}[0-9]$"/>
@samsargent
samsargent / ssh-key-prompt.sh
Last active January 16, 2020 04:38
SSH Login - No Password
#!/bin/bash
echo "Enter ssh username & host you want to add your key to in the following format: username@host.com"
read host
IP=$(curl -Sfs https://wtfismyip.com/text)
KEY=$(cat ~/.ssh/id_rsa.pub)
echo 'Adding Key to '$host': from="'$IP'"' $KEY
echo 'from="'$IP'"' $KEY | ssh $host 'cat >> ~/.ssh/authorized_keys'
exit;
@samsargent
samsargent / download-wordpress.sh
Created July 30, 2015 05:11
Download Latest Wordpress
wget http://wordpress.org/latest.tar.gz && tar xfz latest.tar.gz && rm -rf wordpress/wp-content/ && mv wordpress/* ./ && rm -rf wordpress/ && rm -rf latest.tar.gz
@samsargent
samsargent / snippets.sh
Created October 27, 2015 00:13
SSH Snippets
# for the things I rarely do but often forget
# copy files via ssh
scp foobar.txt your_username@remotehost.com:/some/remote/directory
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"