Skip to content

Instantly share code, notes, and snippets.

@stephenharris
stephenharris / jenkins-ec2-continous-integration.md
Last active May 15, 2023 00:16
How to set up CI with Jenkins on AWS EC2 (and some notes)
@stephenharris
stephenharris / copy-pre.css
Last active May 8, 2023 06:46
Adding a 'copy' button to <pre> content
.pre-wrapper{
position:relative;
}
.pre-wrapper pre{
padding-top: 25px;
}
.pre-wrapper .copy-snippet {
border-radius: 0;
min-width:55px;
background: none repeat scroll 0 0 transparent;
@stephenharris
stephenharris / readme.md
Last active April 10, 2023 06:53
Suppressing comments from git diff of .po files

How to suppress comments when performing git diff on .po files.

Taken from: http://stackoverflow.com/questions/2006351/gettext-po-files-under-version-control

Changes in the codebase can alter line numberings given in .po 'comments'. While such changes should be committed they make obsecure the actual translation changes made, and make auditing them difficult.

  1. Create /usr/local/bin/strippocomments as given in this gist.
@stephenharris
stephenharris / install-firefox-linux.md
Last active April 2, 2023 09:44
Installing a particular version of firefox on Linux.

Installing a particular version of FireFox on Linux

  1. Does an existing version of firefox exist?

    firefox --version
    

    If not, skip to (3).

@stephenharris
stephenharris / pre-tags-in-comments.php
Created August 12, 2013 15:07
Allow pre tags in comments
<?php
/**
* Allow 'pre' tags in comments.
* This is not by default allowed for users who cannot publish 'unfiltered_html'.
* Maybe this should go in WP-MarkDown?
*
*/
add_filter( 'wp_kses_allowed_html', 'myprefix_allow_pre_tags_in_comments', 10, 2 );
function myprefix_allow_pre_tags_in_comments( $tags, $context ){
if( 'pre_comment_content' == $context ){
<?php
/**
* An implementation of the AES cipher (CBC mode).
* For reference http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*
* @author Stephen Harris (contact@stephenharris.info)
* @license GPL
*
* Example usage:
@stephenharris
stephenharris / is-descendent-of.php
Created May 29, 2013 23:26
Check if current page is a descendant of the specified one.
<?php
/**
* Is the current page a descendent of page identified by the path (not slug).
* A page is not a descendent of itself!
* @link http://wordpress.stackexchange.com/questions/101213/does-is-child-exist-in-wp-3-5-1
* @param string $page_path The path of the page, e.g. mypage/mysubpage
* @return boolean True if current page is a descednent of specified $page_path. False otherwise.
*/
function is_descendent_of( $page_path ){
@stephenharris
stephenharris / import-venues.php
Created March 21, 2017 11:12
A WP-CLI command to import a CSV of venues
<?php
/*
Plugin Name: Import Venues WP CLI command
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: Adds `wp eo venue import <path-to-file>` command.
Author: Stephen Harris
Version: 0.1
*/
// Exit if accessed directly
@stephenharris
stephenharris / wp-user-registration-query.php
Last active October 6, 2021 12:55
Get all users registered between two dates
<?php
/*
* Get all users registered after $start and before $end (dates in yyyy-mm-dd format)
*
* Based on my answer to this question: http://wordpress.stackexchange.com/questions/51485/how-can-i-query-all-users-who-registered-today/51492#51492
*
* @param (string) $start - start date in yyyy-mm-dd format
* @param (string) $end - end date in yyyy-mm-dd format
*/
@stephenharris
stephenharris / color_luminance.php
Created May 7, 2013 14:19
Lighten or darken a given colour
<?php
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function color_luminance( $hex, $percent ) {
// validate hex string