Skip to content

Instantly share code, notes, and snippets.

View KnightAlex's full-sized avatar

Alex Knight KnightAlex

  • Devon, United Kingdom
View GitHub Profile
@KnightAlex
KnightAlex / gist:8870374ff1f2b3e22d37
Created July 8, 2014 10:17
Equal height html elements (jQuery)
// Match heights of elements on homepage for uniform display
matchHeight = function() {
//Timeout added to counteract delays in element sizing from loading
setTimeout(function(){
jQuery('.equal').each(function(){
var maxHeight = '0';
jQuery('.equal').each(function(){
maxHeight = (jQuery(this).height() > maxHeight) ? jQuery(this).height() : maxHeight;
});
jQuery('.equal').height(maxHeight);
@KnightAlex
KnightAlex / livetext
Created March 31, 2014 15:59
Show live text as it's being typed (jQuery)
$(document).ready(function(){
$('#mytext').keyup(function(){
$('#carrytext').html(this.value);
});
});
@KnightAlex
KnightAlex / gist:5076630
Created March 3, 2013 15:55
Basic media query breakpoints
/* ------------ RESPONSIVE MEDIA QUERIES ------- */
@media (max-width: 1024px) {
}
/* iPad portrait */
@media (max-width: 768px) {
}
@KnightAlex
KnightAlex / gist:5065357
Created March 1, 2013 15:24
PHP function to shorten a string
function shortenText($text, $chars) {
// Change to the number of characters you want to display
$text = $text." ";
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}
@KnightAlex
KnightAlex / gist:2029130
Last active October 1, 2015 17:17
Wordpress: wp-config switch statement for different environments
switch($_SERVER['SERVER_NAME']) {
//local
case 'localhost':
define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '127.0.0.1');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('WP_DEBUG', true);
@KnightAlex
KnightAlex / snippet.php
Created March 12, 2012 20:30
Wordpress: remove classes from wp_list_pages
// just add this to functions.php
function remove_page_class($wp_list_pages) {
$pattern = '/\<li class="page_item[^>]*>/';
$replace_with = '<li>';
return preg_replace($pattern, $replace_with, $wp_list_pages);
}
add_filter('wp_list_pages', 'remove_page_class');
@KnightAlex
KnightAlex / gist:1989121
Created March 6, 2012 21:43 — forked from padolsey/gist:527683
Javascript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@KnightAlex
KnightAlex / gist:1989091
Created March 6, 2012 21:36
CSS: css reset (Eric Meyer)
/* =Reset default browser CSS. Based on work by Eric Meyer: http://meyerweb.com/eric/tools/css/reset/index.html
-------------------------------------------------------------- */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,