Skip to content

Instantly share code, notes, and snippets.

View rubenvarela's full-sized avatar

Rubén Varela rubenvarela

View GitHub Profile
@rubenvarela
rubenvarela / install.sh
Created August 13, 2020 03:49
Ubuntu 20.04, rclone, VirtualBox guest additions
# update apt repository
sudo apt update
# upgrade packages
sudo apt upgrade
# install rclone
curl https://rclone.org/install.sh | sudo bash
# install htop, bmon, tmux, guest addition dependencies
sudo apt install htop bmon tmux build-essential dkms linux-headers-$(uname -r)
# install guest additions. Make sure it's already inserted.
# get temp directory
@rubenvarela
rubenvarela / README.md
Created March 6, 2020 14:27 — forked from anthumchris/README.md
Clear Nginx Cache

Clearing Nginx's HTTP Cache

I recently implemented Nginx HTTP content caching on our WordPress web servers to improve page load speeds and eliminate redundant, unneeded server-side page rendering. Caching the pages was relatively straightforward, but clearing the cache required a custom workaround.

Nginx comes in two versions: free and “Nginx Plus” at $2,500/year. The free version of Nginx does not offer the needed cache-clearing features of Nginx Plus, and I wasn’t comfortable paying $20,000 for 8 instances without trying to build my own solution.

Our Nginx servers run as an HTTP proxy for multiple PHP/MySQL-backed WordPress sites. The goal was to cache the dynamic PHP HTML responses in Nginx and serve the HTML pages from Nginx to avoid redundant, CPU-intensive PHP renders.

Site Cache Configuration

The example below shows how PHP response caching is configured for a site (other nginx configuration details are excluded for brevity). A cache named cachedemo-prod is defined to store cached HTML f

@rubenvarela
rubenvarela / ac-dump.sh
Created September 22, 2019 17:14
Drupal/Drush - Dump database from alias to file
#!/usr/bin/env bash
##
# Print usage instructions
##
usage() {
echo "Usage:"
echo " ac-dump.sh @alias"
echo " It will copy the database from the alias to a local file named as the alias in gzip format"
echo ""
@rubenvarela
rubenvarela / gist:de82dfd08c013d27cb9753aa102922ce
Last active July 29, 2019 23:11 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another and keep its commit history
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- -- all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@rubenvarela
rubenvarela / up
Created July 2, 2018 23:12 — forked from mayel/up
up - script to keep your Mac up-to-date (OS, Homebrew, and App Store updates) via the command line
#!/bin/sh
# up - v2 - script to keep your Mac up-to-date (OS, Homebrew, and App Store updates) via the command line
# run thus to to install: cd /usr/local/bin && curl -s -O https://gist.githubusercontent.com/mayel/c07bc0acb91824501d5bdbdc9eb7b33a/raw/08821f64c067327ea68a1a817eb43657db10f10e/up && chmod 755 /usr/local/bin/up
# and then run it anytime by simply entering the command: up
# By https://github.com/mayel based on a script by https://github.com/imwally
# homebrew
@rubenvarela
rubenvarela / CacheBuster.js
Last active February 27, 2018 23:37
Bookmarklet to add or increase a query string by 1 (cachebuster). Useful when using caching layers that respect query strings (Cloudflare, Varnish)
javascript:void((function () {
var uri = location.href;
var key = "cachebuster";
var re = new RegExp("([?&])" + key + "=(.*)?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
var matches = uri.match(re);
if (matches) {
location.href = uri.replace(re, '$1' + key + "=" + String(parseInt(matches[2])+1) + '$3');
@rubenvarela
rubenvarela / gist:00e8ecffc9744110b5df
Created June 27, 2015 20:09
programmerexcuses.com Snapshot
Actually, that's a feature
Did you check for a virus on your system?
Don't worry, that value is only wrong half of the time
Even though it doesn't work, how does it feel?
Everything looks fine my end
How is that possible?
I broke that deliberately to do some testing
I can have a look but there's a lot of if statements in that code!
I can't make that a priority right now
I can't test everything
@rubenvarela
rubenvarela / cs_known_hosts
Last active June 28, 2017 19:15
Purdue CS cleaned known hosts
#Extracted from https://www.cs.purdue.edu/resources/facilities/remote-access/ssh_known_hosts2
#removed the key part using searching for ssh-(.*)\n and replacing with \n
# Since the only part I removed was the key, we can asume all the hosts per line identify the same host.
adenine,adenine.cs,adenine.cs.purdue.edu,128.10.8.25
adenine,adenine.cs,adenine.cs.purdue.edu,128.10.8.25
airfix,airfix.cs,airfix.cs.purdue.edu,128.10.2.171
airfix,airfix.cs,airfix.cs.purdue.edu,128.10.2.171
akula,akula.cs,akula.cs.purdue.edu,128.10.8.48
akula,akula.cs,akula.cs.purdue.edu,128.10.8.48
@rubenvarela
rubenvarela / Git links.md
Last active August 29, 2015 14:06
List of Git resources. Tutorials, Workflows and other things I might find interesting.
@rubenvarela
rubenvarela / gist:11332904
Created April 26, 2014 22:31
JS to remove accents in spanish including "diéresis"
accentsTidy = function(s){
var r=s.toLowerCase();
r = r.replace(new RegExp(/\s/g),"");
r = r.replace(new RegExp(/[á]/g),"a");
r = r.replace(new RegExp(/[é]/g),"e");
r = r.replace(new RegExp(/[í]/g),"i");
r = r.replace(new RegExp(/ñ/g),"n");
r = r.replace(new RegExp(/[ó]/g),"o");
r = r.replace(new RegExp(/[úü]/g),"u");
return r;