Skip to content

Instantly share code, notes, and snippets.

View ollietreend's full-sized avatar

Ollie Treend ollietreend

View GitHub Profile
@ollietreend
ollietreend / .screenrc
Created February 26, 2015 13:42
.screenrc config
# Tabs in status bar
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# Disable epilepsy triggers
vbell off
# Enable scrolling
termcapinfo xterm ti@:te@
@ollietreend
ollietreend / image.php
Last active December 7, 2016 16:28 — forked from anonymous/WordPress disable the attachment page by redirecting
Disable WordPress media attachment page by redirecting to the parent post. Original idea from: http://www.wpbeginner.com/wp-tutorials/how-to-disable-image-attachment-pages-in-wordpress/
<?php
/**
* Disables the media attachment page by redirecting the user elsewhere.
* Save as 'image.php' in theme.
* Inspired by http://www.wpbeginner.com/wp-tutorials/how-to-disable-image-attachment-pages-in-wordpress/
*/
if ($post->post_parent) {
wp_redirect(get_permalink($post->post_parent), 301);
} else {
@ollietreend
ollietreend / acf-php-to-json.php
Last active September 18, 2024 05:24
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@ollietreend
ollietreend / functions.php
Created August 16, 2017 09:31
WordPress admin bar bump for Bootstrap fixed navbar
<?php
namespace MyTheme;
function setup() {
add_theme_support('admin-bar', ['callback' => __NAMESPACE__ . '\\admin_bar_bump']);
}
add_action('after_setup_theme', __NAMESPACE__ . '\\setup');
/**
@ollietreend
ollietreend / functions.php
Created September 4, 2017 17:03
Get a WordPress attachment ID given its URL
<?php
/**
* Get attachment ID from its URL
*
* @param string $url
* @return bool|int The Attachment ID or false if not found
*/
function get_attachment_id_from_src($url) {
if (($pos = strpos($url, '/uploads/')) === false) {
@ollietreend
ollietreend / decode-kube-secret.sh
Last active June 25, 2022 11:11
Decode Kubernetes secrets
# Get secret from Kube and pipe to jq to parse and base64 decode
kubectl get secret name-of-the-secret -o JSON | jq '.data | map_values(@base64d)'
@ollietreend
ollietreend / longest_records.rb
Created January 28, 2022 18:19
Find the records with the longest TEXT columns in a Rails + MySQL app's database tables.
ActiveRecord::Base.connection.tables.map { |table|
text_columns = ActiveRecord::Base.connection.columns(table).select { |c| c.type == :text }
text_columns.map { |col|
longest_record = ActiveRecord::Base.connection.exec_query("SELECT id, LENGTH(#{col.name}) as length FROM #{table} ORDER BY length DESC LIMIT 1").rows.first
{
table: table,
column: col.name,
record_id: longest_record.first,
length: longest_record.last,
}
@ollietreend
ollietreend / uninstall_gems.sh
Created June 25, 2022 11:20
Uninstall all gems from all Ruby versions managed by rbenv
#!/usr/bin/env bash
# Uninstall all gems from all Ruby versions managed by rbenv
uninstall_gems() {
gems=$(gem list --no-versions)
for gem in $gems; do
gem uninstall $gem -aIx
done
gem list