Skip to content

Instantly share code, notes, and snippets.

@NeilJS
NeilJS / gist:32ac664f846bdea9aac25a428fe3727a
Created September 30, 2019 08:24
Chrome snippet: designMode="on" + kill all links
// Disable anchor links
window.addEventListener("click", function (event) {
event.preventDefault();
});
// Disable click eventlisteners
window.addEventListener("click", function (event) {
event.stopPropagation();
}, true);
// design mode on
document.designMode = "on";
049e0cd87735e5682ccd20f6017e7d72e540eda8fe0344d3a5d24c6f37ab692952d678dfa729069abcd475de9321354639f1ea6c6e57c21c2a9d493fb50fdf5832;callmejimmyj
@NeilJS
NeilJS / sslcrt-with-subjectAltName.txt
Last active March 2, 2023 20:20
Generate self-signed ssl cert (Virtualbox Ubuntu) - fix for Chrome 58 requirement for subjectAltName / Subject Alternative Name
# Update refs to .example.com
sudo su
openssl req -x509 -nodes -sha256 -days 3650 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -new -out /etc/apache2/ssl/apache.crt -subj /C=GB/ST=London/L=London/O="Company Name"/OU=Team/CN=www.example.com -reqexts SAN -extensions SAN -config <(cat /usr/lib/ssl/openssl.cnf <(printf '[ SAN ]\nsubjectAltName=DNS:www.example.com,DNS:example.com,DNS:*.example.com'))
exit
sudo service apache2 restart
# On Windows, trust the certificate: save the new certificate from Chrome to desktop (via Devtools > Security > View > Details > Copy to file; use DER option)
# May need to delete any previously imported certificates via mmc (on Windows)
# Run mmc; add the Certificates snap-in; import from desktop to 'Trusted Roots Certification Authorities' and also 'Other People'
# May need to clear Chrome history + SSLs (Settings > Network > Change proxy settings... > Content > Clear SSL state)
@NeilJS
NeilJS / gist:6ff52bcd4c9a91435a35
Created February 12, 2015 09:59
Responsive text - dynamic body font size
<!DOCTYPE html>
<html lang="en" class="js">
<head>
<meta charset="UTF-8">
<title>Responsive text sizes</title>
<style>
h1 {font-size: 1.6em;}
p {font-size: 1em;}
@NeilJS
NeilJS / gist:6726336
Created September 27, 2013 09:50
Get array of categories/tags/custom taxonomy objects (as opposed to just outputting html or a list), for further manipulation. This is a slightly modified version of wp_list_categories() - but saved in functions.php!
function wp_get_categories( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'show_option_none' => __('No categories'),
'orderby' => 'name', 'order' => 'ASC',
'style' => 'list',
'show_count' => 0, 'hide_empty' => 1,
'use_desc_for_title' => 1, 'child_of' => 0,
'feed' => '', 'feed_type' => '',
'feed_image' => '', 'exclude' => '',
'exclude_tree' => '', 'current_category' => 0,
@NeilJS
NeilJS / gist:5900183
Created July 1, 2013 11:51
Create a div shortcode - so you can wrap content in a div in the WordPress editor. Usage: [div id="ID" class="CLASS"]xxxx[/div]
# For Functions.php
// DIV SHORTCODE. Usage: [div id="ID" class="CLASS"]xxxx[/div]
function createDiv($atts, $content = null) {
extract(shortcode_atts(array(
'id' => "",
'class' => "",
), $atts));
return '<div id="'. $id . '" class="'. $class . '" />' . $content . '</div>';
}
add_shortcode('div', 'createDiv');
@NeilJS
NeilJS / gist:5487368
Created April 30, 2013 08:24
Fade in elements in consecutive order.
// Fade in divs consecutively (optional delay)
var delayBetweenEach = 300;
var fadeSpeed = 400;
$(".myDiv").delay(1000).each(function(index) {$(this).delay(delayBetweenEach*index).fadeIn(fadeSpeed);});
@NeilJS
NeilJS / gist:4269982
Created December 12, 2012 17:49
jQuery fix for click events in iOS
// Using Modernizr to detect mobile in this case. More specific for iOS may be better.
var event = (Modernizr.touch) ? "touchstart" : "click";
$("#element").bind(event, function(e) {
// do it
}
@NeilJS
NeilJS / Twitterify
Created August 10, 2012 09:11
Convert plain twitter urls, usernames, hashtags into clickable hyperlinks
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret);
return $ret;
}
#Thanks: http://www.snipe.net/2009/09/php-twitter-clickable-links/
@NeilJS
NeilJS / gist:2916810
Created June 12, 2012 10:35
Get tag id by name
<?php
function get_tag_id_by_name($tag_name) {
global $wpdb;
$tag_ID = $wpdb->get_var("SELECT * FROM ".$wpdb->terms." WHERE `name` = '".$tag_name."'");
return $tag_ID;
}
?>