Skip to content

Instantly share code, notes, and snippets.

@gwire
gwire / wordpress_login_throttle_nginx.md
Created December 13, 2022 22:43
Rate-limiting WordPress login attempts with nginx

One annoyance of running a publically-accessible WordPress site is the bots that attempt to rapidly try thousands of login attempts via /wp-login.php.

Even if none of the guesses are ever likely to work, the site will waste resources running PHP and SQL to confirm that to be the case.

A barrier to these drive-by hack attempts can be added using nginx's http_limit_req, where rate limiting is applied only to POST requests for the login page, not affecting the rest of the site.

  1. In /etc/nginx/conf.d/login-limit.conf we create the zone LOGINLIMIT. 1m is the size of the shared memory zone for tracking requests, and 15r/m limits to 15 requests per minute (ie 1 every 4 seconds).

@gwire
gwire / wordpress_social_rel.php
Last active November 21, 2022 10:24
Adding rel="me" to WordPress social link block items
<?php
/**
* Mastodon accounts can be verified by adding a rel="me" link in the basic rendered html.
* While a <link/> could be added, it seemed like the existing social-links block should be
* the place to add it, but there's currently no way to specify "rel" values in the UI.
*
* Currently only adds to "mastodon" links, but could probably be added to others.
*/
add_filter('render_block', 'social_rel_me', 10, 2);
function social_rel_me($block_content, $block) {
@martinchapman
martinchapman / mosaic.sh
Last active May 18, 2023 15:25
Visualise a latex document git history
# Visualise a latex document git history
# loop through commits, create a PDF from your main file for each
# translate the pages of that PDF to a single image
# create GIF/mp4 from the folder of images created
# run within your local repository
# prerequisites: ImageMagick and FFmpeg
# create output folder
@mlent
mlent / social-sharing-buttons.html
Last active February 24, 2023 08:22
Social sharing buttons
<ul>
<li>
<a href="https://twitter.com/share?text=TITLE OF YOUR POST via @YOUR_USERNAME&url=HTTPS://YOUR_WEBSITE.COM" onclick="window.open(this.href, 'twitter-share', 'width=550,height=235'); return false;">
Share on Twitter
</a>
</li>
<li>
<a href="https://news.ycombinator.com/submitlink?u=HTTP://YOUR_URL.COM&t=YOUR CONTENT" onclick="window.open(this.href, 'hn-share', 'width=550,height=350'); return false;">
Share on Hacker News
</a>
#post-list .post .post__img {
position: absolute;
margin-left: -200px !important;
display: block;
}
.post .post__img img, img.markdown-inline-img {
height: 20px !important;
width: auto !important;
from sre_parse import Pattern, SubPattern, parse as sre_parse
from sre_compile import compile as sre_compile
from sre_constants import BRANCH, SUBPATTERN
class Scanner(object):
def __init__(self, tokens, flags=0):
subpatterns = []
pat = Pattern()
# This file modifies benchmark-ips to better accommodate the optimisation
# characteristics of sophisticated implementations of Ruby that have a very
# large difference between cold and warmed up performance, and that apply
# optimisations such as value profiling or other speculation on runtime values.
# Recommended to be used with a large (60s) warmup and (30s) measure time. This
# has been modified to be the default. Note that on top of that, it now runs
# warmup five times, so generating the report will be a lot slower than
# before.
# Code is modified from benchmark-ips
@smarr
smarr / truffle-material.md
Last active March 16, 2023 14:06
Truffle: Languages and Material
@jamesarosen
jamesarosen / two-travis-builds.md
Last active June 5, 2021 18:39
Running Two Very Different Travis Builds

I have a project that's been happily chugging along on Travis for a while. Its .travis.yml looks something like

script:
  - node_modules/ember-cli/bin/ember test

I wanted to add a second parallel build that did something very different. I didn't want to run ember test with a different Ember version or some other flag. I wanted to run a completely different command. Specifically, I wanted to run LicenseFinder's audit.

Travis has great docs on customizing parallel builds, but nothing describes how to do two completely different commands.