Skip to content

Instantly share code, notes, and snippets.

View hampusn's full-sized avatar

Hampus Nordin hampusn

View GitHub Profile
@hampusn
hampusn / jira-filters.md
Last active December 16, 2015 10:19
Various issue filters for JIRA.
@hampusn
hampusn / hampusn_money_filter.rb
Created July 3, 2014 09:13
Liquid filter which formats a float with two decimals. Example usage: <p>Price: {{ 95.5 | hampusn_money }}</p>
module Jekyll
module HampusnMoneyFilter
def hampusn_money(money)
return '' if money.nil?
sprintf("%0.02f", money)
end
end
end
Liquid::Template.register_filter(Jekyll::HampusnMoneyFilter)

Keybase proof

I hereby claim:

  • I am hampusn on github.
  • I am hampus (https://keybase.io/hampus) on keybase.
  • I have a public key whose fingerprint is 1D87 8F65 6203 5921 3AA3 B9EA 4845 51B3 D2AB DF4A

To claim this, I am signing this object:

# Google Analytics & Campaign Monitor
# Removes all query params where the key begins with "utm_"
# Skip the rewrites if no "utm_*" key exist.
RewriteCond %{QUERY_STRING} !(^|&)utm_ [NC]
RewriteRule .* - [S=3]
# Check and handle first query param.
RewriteCond %{QUERY_STRING} ^utm_[A-Za-z0-9]+=[^&]+(.*) [NC]
RewriteRule (.*) /$1?%1 [R=301,L]
@hampusn
hampusn / functions.php
Last active August 29, 2015 14:16
Fix for ACF + WP Media Folder (ACF admin stops working due to javascript error in WP Media Folder)
<?php
/**
* Fixes issue where JS is halted on ACF admin pages when WP Media Folder is activated.
*
* These are the versions of the plugins I had when I tried
* - WP Media Folder - 1.0.4
* - Advanced Custom Fields Pro - (5.1.8, 5.2.1)
*
*
@hampusn
hampusn / cleanup-transmission-list.sh
Last active June 12, 2024 05:39
A script which removes torrents from transmission when they are completed and stopped. Developed for Synology DiskStation as a cron job.
#!/bin/sh
# Called with the credentials for the rpc-username and rpc-password:
# ./cleanup-transmission-list.sh username password
# Exit early if user and pass is not passed as arguments
if [ "$1" == "" ] || [ "$2" == "" ]; then
exit 0;
fi
@hampusn
hampusn / wp-switch-domain.sql
Last active September 30, 2015 08:15
SQL queries to switch domain on WP site.
# If you get an error about illegal mixes of collation you might need to force the collation.
# SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';
SET @old_url = 'http://www.oldurl.com';
SET @new_url = 'http://www.newurl.com';
UPDATE wp_options SET option_value = replace(option_value, @old_url, @new_url) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @old_url, @new_url);
UPDATE wp_posts SET post_content = replace(post_content, @old_url, @new_url);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @old_url, @new_url);
@hampusn
hampusn / cleanup-xliffs.php
Last active August 29, 2015 14:21
PHP CLI script for removing specific XMLNodes from WPML Xliff files.
<?php
/**
* Cleanup Xliffs
*
* This file can be called through the php cli and clean up xliff files.
*
* The script takes directories and/or xliff files and removes XML nodes which
* matches the XPath query.
*
* @author Hampus Nordin <hej@hampusnord.in>
@hampusn
hampusn / wpml-detach-duplicates.sql
Created June 11, 2015 07:39
SQL queries to detach WPML duplicates and translate them separately.
# Select all posts which are duplicates of a language.
# The language parameter is to only select by the new language (not the original duplication language).
SET @lang_code = 'da';
SELECT pm.*, p.post_title, p.post_type, icl.language_code
FROM wp_postmeta pm
INNER JOIN wp_icl_translations icl ON icl.element_id = pm.post_id
INNER JOIN wp_posts p ON p.`ID` = pm.post_id
WHERE meta_key='_icl_lang_duplicate_of' AND icl.language_code = @lang_code;
@hampusn
hampusn / functions.php
Last active December 13, 2015 11:44
FB: ACF field to body_class() via filter
<?php
/**
* WP Filter which adds acf field value to body classes for all pages but home.
*
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class
*/
function THEME_NAME_body_class( $classes ) {
if ( function_exists( 'get_field' ) && ! is_home() ) {
$classes[] = get_field( 'page_background' );