Skip to content

Instantly share code, notes, and snippets.

View philgyford's full-sized avatar

Phil Gyford philgyford

View GitHub Profile
@philgyford
philgyford / admin.py
Created August 4, 2022 09:47
A quick Django blog app.
from ckeditor.widgets import CKEditorWidget
from django import forms
from django.contrib import admin
from django.db import models
from django.utils import timezone
from .models import Post
class PostAdminForm(forms.ModelForm):
@philgyford
philgyford / list-custom-taxonomy-widget.php
Last active November 28, 2020 15:42
A modified version of the WordPress List Custom Taxonomy Widget plugin, to enable limiting the number of items shown
<?php
/**
* Plugin Name: List Custom Taxonomy Widget
* Plugin URI: http://celloexpressions.com/plugins/list-custom-taxonomy-widget
* Description: Widget that displays category listings for custom post types (custom taxonomies).
* Version: 4.1
* Author: Nick Halsey
* Author URI: http://celloexpressions.com/
* Tags: custom taxonomy, custom tax, widget, sidebar, category, categories, taxonomy, custom category, custom categories, post types, custom post types, custom post type categories
* License: GPL
@philgyford
philgyford / functions.php
Last active September 4, 2019 07:18
Sparkling WordPress theme, child
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parent_style = 'sparkling-style'; // This is 'sparkling-style' for the sparkling theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
@philgyford
philgyford / article.html
Created March 15, 2019 16:17
Example of how to add a form to every instance of a type of Wagtail CMS Page, without having to manually build the page for each new page in the Admin
{% extends "base.html" %}
{% block content %}
<p>(Article content here.)</p>
<p>Send us your thoughts:</p>
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
@philgyford
philgyford / postgres_migrate_to_sqlite3.md
Last active March 10, 2018 13:15
Migrating a Django postgresql database to sqlite3

Migrating a Django postgresql database to sqlite3

I wanted to export data from a few Django apps, held in a postgres database, and import that data into an sqlite3 database to run locally.

This worked for me, but I'm sure there are other wrinkles, depending on your use of postgres-specific features, etc.

  1. Export the data from postgres
@philgyford
philgyford / README.md
Created January 5, 2018 11:56
Find and replace text in Django objects' fields

Django Find and Replace

This was used to replace all the instances of old Media URLs with new ones, but could be used for any kind of text search/replace across Django objects.

  1. Change the model import to whatever your app and model is.
  2. Set the to_find and to_replace strings to whatever you need.
  3. Change Post to your model name, and the fields to whatever field(s) you want to search and replace across.
@philgyford
philgyford / .gitignore
Last active March 1, 2023 09:18
A script for importing images, and data about them in a CSV file, into WordPress
images/*
*.csv
@philgyford
philgyford / .block
Last active December 12, 2017 04:14
Book series years chart
license: cc-by-sa-4.0
height: 1200
scrolling: no
border: yes
@philgyford
philgyford / resource_usage.py
Created July 22, 2017 13:56
File for displaying %CPU and RAM usage on a system. Not sure where I got this from originally.
#!/usr/bin/env python2.7
import subprocess
import sys
import re
import os,pwd
from pprint import pprint
class TerminalController:
"""
@philgyford
philgyford / .block
Last active December 12, 2017 04:14
D3.js v4 Ladder Graph
license: cc-by-sa-4.0
height: 570
scrolling: no
border: yes