Skip to content

Instantly share code, notes, and snippets.

View fieldoffice's full-sized avatar
🚲
Out cycling

Andy Field fieldoffice

🚲
Out cycling
View GitHub Profile
@fieldoffice
fieldoffice / jquery-clone
Last active August 23, 2016 11:17
jQuery Clone
/* CLONE */
var regex = /^(.+?)(\d+)$/i;
var cloneIndex = $('.cloneme').length;
function clone(){
$(this).parents('.form-element-group').find('.cloneme').eq(0).clone()
.appendTo('.form-element-group-repeater')
.attr("id", "cloneme" + cloneIndex)
.find("*")
.each(function() {
@fieldoffice
fieldoffice / sass-lighten-darken
Created February 26, 2016 15:16
Sass Lighten and Darken Mixins
// Lighten a colour
@function tint($color, $percentage) {
@return mix(white, $color, $percentage);
}
// Darken a colour
@function shade($color, $percentage) {
@return mix(black, $color, $percentage);
}
@fieldoffice
fieldoffice / responsive-sparklines
Created January 22, 2016 11:38
Responsive Sparklines
$(function() {
var sparklineLogin = function() {
$('#mysparkline').sparkline(
[ 42,52,63,12,18,23,45,78,92,87 ],
{
type: 'line',
width: '100%',
height: '40px'
}
<select name="countries">
<option value="" selected>Select a country...</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ">Antarctica</option>
@fieldoffice
fieldoffice / kill-emojis
Created May 6, 2015 20:44
Remove emojis introduced in WordPress 4.2
// Add to your WP functions file
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); //Remove emojis introduced by WP 4.2
remove_action( 'wp_print_styles', 'print_emoji_styles' ); //Remove emojis introduced by WP 4.2
@fieldoffice
fieldoffice / Retina OSX Cursors
Last active August 29, 2015 14:18
Location of Retina OSX Cursors
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HiServices.framework/Versions/A/Resources/cursors
@fieldoffice
fieldoffice / toggle-text
Created March 16, 2015 12:35
Toggle Text (Accordion)
$('.toggle').click(function() {
var txt = $(this).next('ol').is(':visible') ? '+' : '-';
$(this).find('span').text(txt);
$(this).next('ol').slideToggle();
});
<h3 class="toggle">Header <span>-</span></h3>
<ol>
<li>Option 01</li>
<li>Option 02</li>
@fieldoffice
fieldoffice / custom-posts-in-search-results
Last active August 29, 2015 14:17
Wordpress - include custom posts in search results
function include_post_types_in_search($query) {
if(is_search()) {
$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
$searchable_types = array();
if($post_types) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set('post_type', $searchable_types);
@fieldoffice
fieldoffice / querystringredirect
Created March 14, 2015 19:34
.htaccess query string redirect
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^news/article\.php$ /news/? [R=301,L]
@fieldoffice
fieldoffice / exporttocsv
Created March 14, 2015 11:20
Export to CSV (MySQL)
<?php
$conn = mysqli_connect('localhost','user','pw') or die(mysqli_error());
$db=mysqli_select_db($conn,'database') or die(mysqli_error());
$filename = 'filename-' . date("d-m-Y") . '.csv';
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-Description: File Transfer' );
header( 'Content-type: text/csv' );
header( "Content-Disposition: attachment; filename={$filename}" );