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: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,
@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 / 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: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 / 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: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 / 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: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 / gist:9cfe0da49683fe577a27
Last active August 29, 2015 14:04
Woothemes Flexslider - responsive height fix
function fixHeight() {
var maxHeight = 0,
slides = el.find('.slides'),
data = el.data('flexslider');
slides.children()
.height('auto')
.each(function() {
maxHeight = Math.max(maxHeight, $(this).height());
})
.height(maxHeight);
@KnightAlex
KnightAlex / gist:1f2c710b234ce65c5765
Last active March 24, 2016 10:47
WordPress sample page/post content
<h1>Heading 1</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et mattis nulla. Quisque volutpat arcu et accumsan tincidunt <strong>this is bold</strong>. <em>This is italic</em> Cras non lorem dui. Aenean quis erat mi. Sed metus ligula, varius quis lacinia at, rhoncus in est. Donec <a href="http://www.google.com">this is a link</a>. Fusce facilisis, nisi sed egestas euismod, tortor turpis tincidunt leo, sit amet aliquet nulla elit in nulla. Mauris dapibus varius quam eget interdum. Maecenas libero purus, egestas et interdum nec, semper in nulla. Curabitur a neque posuere, ullamcorper nibh vel, vestibulum libero. Maecenas commodo ipsum id risus euismod, ut mollis massa posuere. In eget vestibulum dolor, vel scelerisque magna. Nulla non sapien eu elit posuere hendrerit.
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<img class="alignright" src="https://placeimg.com/300/400/any" alt="" width="300" height="400" />Ut in nisl ligula. Vivamus et d