Skip to content

Instantly share code, notes, and snippets.

View jonesch's full-sized avatar

Christopher W. Jones jonesch

View GitHub Profile
@jonesch
jonesch / htaccess-cheat-sheet.txt
Created November 1, 2018 14:54
htaccess for SEO
# Syntax highlights
# ===========================
# Flags for a Rule, by default R=302, L equals Last line to run & stop the file
[R=301,L]
# This is an Apache setting that is normally turned on by default at the server level
RewriteEngine on
# Single vs Plural
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
// Pull our WP Theme Header
get_header();
// Pull our WP Theme Footer
get_footer();
@jonesch
jonesch / mail-chimp-subscribe
Last active December 29, 2015 10:39
AJAX PHP Processor - Mail Chimp List Subscribe v2.0
//create a clean array of data to be posted
foreach($_POST as $key => $val) {
$user_input[$key] = htmlentities(stripslashes(trim($val)), ENT_QUOTES, 'UTF-8');
}
// There are two unique parts to this URL. The First is the "us3" portion of the URL is specific to your account. The second is the file extension at the end is what is returned, you can set it to json, php, or xml, but json is default.
$post_url = 'https://us3.api.mailchimp.com/2.0/lists/subscribe.json?';
// Let's put together our user data to send
$post_query_array = array(
@jonesch
jonesch / global-sprite
Created October 8, 2013 19:32
Simple Mixin for Global Sprite
// Setup
@mixin global-sprite($x-value, $y-value){
background: transparent url(../img/sprite-global-assets.png) $x-value $y-value no-repeat;
}
// Usage
@include global-sprite(0, -40px);
@jonesch
jonesch / gist:6637312
Created September 20, 2013 13:13
Generic JS Form validation
$('.general-contact-form').submit(function(){
var req_values = ['user_name', 'user_email_address', 'user_phone_number', 'user_interest_in'],
empty_fields = false;
for (var i = 0; i < req_values.length; i++) {
if($('#'+req_values[i]).val() == ''){
$('#'+req_values[i]).addClass('required');
empty_fields = true;
}
}
if(empty_fields === true || ){
@jonesch
jonesch / Placeholder-Fallback
Created August 13, 2013 21:45
Simple Placeholder Fallback that is dependent on Modernizer. I am sure there is a cleaner way, but I just wanted to see if I could do it from scratch.
if(!Modernizr.input.placeholder) {
$('[placeholder]').each(function(i){ $(this).val($(this).prop('placeholder')); });
$('[placeholder]').on({
'focus' : function(evt){
if($(this).val() === $(this).prop('placeholder')) { $(this).val(''); }
},
'blur' : function(evt){
if($(this).val() !== $(this).prop('placeholder')) { $(this).val($(this).prop('placeholder')); }
}
});
@jonesch
jonesch / gist:5153018
Created March 13, 2013 15:07
Here is a SASS file that will help with theming your Wordpress Login page.
@import "compass";
body.login {
// background: transparent url(../img/bg-footer.png) 0 0 repeat;
h1 {
text-align: center;
a {
width: 320px;
height: 92px;
// background: url(../img/logo-login.png) 0 0 no-repeat;
@jonesch
jonesch / gist:4072127
Created November 14, 2012 13:42
Downloading Flickr photos
<?php // Let's go get some flickr photos. Key and Set are defined in the uploader.
$query = 'http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key='.$apiKey.'&photoset_id='.$photoset_id.'&extras=url_o,url_c&format=php_serial';
$ch = curl_init(); // open curl session
// set curl options
curl_setopt($ch, CURLOPT_URL, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch); // execute curl session
@jonesch
jonesch / htaccess - mobile redirects
Created November 2, 2012 12:39
Catswhocode - Mobile .htaccess redirects
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/m/.*$
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
@jonesch
jonesch / mail-attachment-wordpress
Created October 22, 2012 12:40
Attaching & Validating A File. Wordpress
if(!empty($_FILES['resume']['name'])){ // check to see if we have a photo and a user clicks submit
$accept_file_formats = array(
'image/jpg',
'image/jpeg',
'image/png',
'image/gif',
'text/rtf', //.rtf file
'text/plain', //.txt file
'application/msword', //.doc file
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', //.docx file