Skip to content

Instantly share code, notes, and snippets.

View gordjw's full-sized avatar

Gordon Williamson gordjw

View GitHub Profile
@gordjw
gordjw / Leetcode 80 - Medium - Remove duplicates from sorted array #2
Last active February 6, 2024 22:24
Space efficient solution for Leetcode 80
"""
Basic solution
Time: O(nlogn)
- The main loop iterates through the original list (n + k) times
- The inner loop iterates through the tail of the list (k * log(n))
- In the worst case, k would be n/3, which means:
- main loop reduces to n + n/3 -> 4/3 * n -> n
- inner loop reduces to n/3 * log(n) -> log(n)
Space: O(n)
@gordjw
gordjw / Leetcode 2058 - O(n) solution.py
Last active February 6, 2024 02:39
Leetcode 2058 - Medium - Find the Minimum and Maximum Number of Nodes Between Critical Points
"""
We can optimise by recognising that:
- max_dist will always be (last - first)
- min_dist will always be from one pair of adjacent critical points, so we can calculate it as we run through the list
Time: O(n)
- We only run through the linked list once
Space: O(n)
- We create only a handful of extra variables, none of which are iterables or callables
"""

Keybase proof

I hereby claim:

  • I am gordjw on github.
  • I am gordjw (https://keybase.io/gordjw) on keybase.
  • I have a public key ASDt3_xzHZYux1RDUsBnOyZ8YRo5gzw46b1P4KcK-37Ajgo

To claim this, I am signing this object:

@gordjw
gordjw / panda.sh
Created January 4, 2016 23:27
Watches a directory for Markdown file (*.md) changes, and refreshes output formats (PDF, DOCX, RTF)
#!/bin/bash
#
# Panda
#
# Watches a directory for Markdown file (*.md) changes, and refreshes output formats (PDF, DOCX, RTF)
#
PANDOC=`/usr/bin/which pandoc`
PANDOC_IN=/tmp/pandoc/in/
@gordjw
gordjw / my-analytics-event.php
Created July 3, 2015 01:48
Example of adding an analytics event to track WordPress backend usage
add_filter( 'tss_analytics_events', 'add_my_analytics_events' );
function add_my_analytics_events( $events ) {
$events['publish_post'][] = array( 'post', 'published', function( $args ) { return $args[0]; } );
}
@gordjw
gordjw / wp-config.php
Created June 4, 2015 12:38
wp-config file to serve core and wp-content from different directories
<?php
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
define('WP_CONTENT_DIR', '/data/www/web/wp-content');
// is_ssl doesn't always work, e.g. behind load balancers
if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || is_ssl())
define('WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/wp-content');
else
@gordjw
gordjw / wordpress
Created June 4, 2015 12:21
Nginx config file to serve wordpress core and wp-content from different directories
server {
listen 443 ssl;
listen 80;
root /data/www/web/core;
server_name web;
server_name_in_redirect off;
client_max_body_size 100m;
index index.php index.html index.htm;
@gordjw
gordjw / piwik-fixer.php
Last active August 29, 2015 14:21
WP Piwik fixer
<?php
/*
Plugin Name: Quick and Dirty WP-Piwik Fixer
Description: Temporary WP-Piwik Fixer, tested with WP-Piwik 0.9.9.18 and Piwik 2.9.1. Fixes site ids stored in WP Option tables in case yours have become messed up.
*/
// Quick and dirty, don't install if you don't have shell or FTP access. It will takeover your admin screens.
// Commented out the line below to stop people from accidentally installing and killing wp-admin
// Uncomment to enable, recomment to disable. You won't have wp-admin access while it's enabled.
@gordjw
gordjw / gist:b8616b7834addc91a6b1
Created May 5, 2015 10:31
Comparison of git and svn checkout and updates
In which I run some pretty rudimentary tests to find the most efficient way to checkout/update WordPress with git, and compare it to SVN.
First, we'll try shallow cloning, because that's the path to the smallest local git repository.
$ git clone --depth 1 https://github.com/WordPress/WordPress.git --branch 4.1
Cloning into 'WordPress'...
remote: Counting objects: 1421, done.
remote: Compressing objects: 100% (1276/1276), done.
remote: Total 1421 (delta 163), reused 982 (delta 118), pack-reused 0
Receiving objects: 100% (1421/1421), 7.96 MiB | 1.35 MiB/s, done.