Skip to content

Instantly share code, notes, and snippets.

Sam Sargent samsargent

  • Vivo Group
  • Brisbane, Australia
View GitHub Profile
@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];
}
View snippets.sh
# for the things I rarely do but often forget
# copy files via ssh
scp foobar.txt your_username@remotehost.com:/some/remote/directory
@samsargent
samsargent / download-wordpress.sh
Created Jul 30, 2015
Download Latest Wordpress
View download-wordpress.sh
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 / ssh-key-prompt.sh
Last active Jan 16, 2020
SSH Login - No Password
View ssh-key-prompt.sh
#!/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;
View Sublime Terminal Sym Link
View Parsely.js Mobile Number Validation
<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 / 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";
You can’t perform that action at this time.