Skip to content

Instantly share code, notes, and snippets.

@axeleroy
axeleroy / .htaccess
Last active Mar 29, 2018
Force HTTPS on Wordpress sites
View .htaccess
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.tld/$1 [R,L]
# Replace domain.tld by you own domain name ;-)
# BEGIN WordPress
@axeleroy
axeleroy / sshrc
Last active Oct 2, 2019
Send Pushbullet notification on SSH connection
View sshrc
#!/bin/bash
access_token=<pushbullet access token> # Get it from your account settings page (https://www.pushbullet.com/#settings/account)
# Get IP, reverse DNS and hostname
ip=${SSH_CONNECTION%% *}
reverse=$(dig -x $ip +short)
hostname=$(hostname)
curl --request POST \
@axeleroy
axeleroy / markdown-img-picture-replacement.rb
Created May 29, 2020
Jekyll plugin that replaces pictures in Markdown documents by responsive images using jekyll-responsive-mage
View markdown-img-picture-replacement.rb
Jekyll::Hooks.register :documents, :pre_render do |document, payload|
docExt = document.extname.tr('.', '')
# only process if we deal with a markdown file
if payload['site']['markdown_ext'].include? docExt
newContent = document.content.gsub(/!\[(.*)\]\((?:\/?([^\)\:\s]+))(?:\s"(.*)")?\)(?:{:([^}]+)})*/, '{% responsive_image path: \2 alt: "\1" title: "\3" %}')
document.content = newContent
end
end
@axeleroy
axeleroy / wxr_utils.py
Created Apr 19, 2020
Python library for generating WXR files
View wxr_utils.py
"""Utility functions to create a WXR file for Wordpress.
"""
import datetime
import os
from lxml import etree as ET
from lxml.etree import CDATA
# XML namespaces declarations