Skip to content

Instantly share code, notes, and snippets.

@twkm
twkm / Live or Staging Environment Git Remote Repo Setup.md
Last active May 8, 2018 02:19
A process to create a git remote repo for live or staging servers, automatically updating on those environments from local dev.

Setting up a web server to track a repo

A setup to allow pushing to live/staging from a local repo. This is mostly a reference that I can return to later, but maybe it will be helpful to you too!

Improvements to this process

The process could use some improvements

  • Handle conflicts automatically in the post-receive script
@twkm
twkm / responsive-video-wrapper.md
Last active August 24, 2016 22:35
Responsive Video Wrapper

padding-bottom is calculated using the aspect ratio of the video. a 16:9 video has a padding-bottom of 56.25%, while a 4:3 video has a padding-bottom of 75%.

More detailed article at Smashing Magazine

.videowrapper {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 35px;
    height: 0;

Conditional X-Robots-Tag Header

This apache configuration can be added to the .htaccess file of a site to automatically keep staging and development versions from being indexed by Google and other search engines. No more worrying about whether or not noindex is keeping live sites from being crawled by search engines!

.htaccess configuration

# Check HTTP_HOST variable and set noindex, nofollow for hosts other than the live site
<IfModule mod_rewrite.c>
	RewriteCond %{HTTP_HOST} ^domain\.com$

.htaccess Reference

A collection of useful .htaccess snippets for SEO and development.

Redirect naked domain to www subdomain

# Redirect naked domain to www subdomain
<IfModule mod_rewrite.c>
RewriteEngine On
@twkm
twkm / schema-json-ld-google-tag-manager.md
Last active August 9, 2016 17:05
Quick reference for inserting JSON-LD in a page to use for Schema.org purposes within Google Tag Manager.

Schema.org JSON-LD in Google Tag Manager

Quick reference for inserting JSON-LD in a page to use for Schema.org purposes within Google Tag Manager.

From this excellent Moz post.

<script>
    (function()
    {
@twkm
twkm / jquery-cdn-fallback.md
Last active November 9, 2016 16:40
Snippet to load jQuery via Google Hosted Libraries, fallback to local version.

Load jQuery via Google Hosted Libraries

Loading jQuery via a Google Hosted Libraries allows it to load quicker, as other sites who have included it from Google's Hosted Libraries will ensure that jQuery is already available in the cache of many of your visitors' computers.

The following snippet of code will attempt to load jQuery from Google Hosted Libraries and fall back to a local version if it did not load correctly for any reason. Ensure that you update the path to your local version of jQuery in the code below.

<!-- Load jQuery via Google CDN, fall back to local version if not loaded -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
@twkm
twkm / awk-geolite
Last active February 3, 2017 23:20
AWK scripts to process GeoLite2 Database
## Get Countries
gawk '
BEGIN {
FS="\"*,\"*"
OFS="\",\""
print "\"" "id", "name", "slug" "\""
}
NR>1 {
slug = tolower($2)
@twkm
twkm / vpnkillswitch.sh
Created April 20, 2017 14:52
General VPN Killswitch using UFW
#!/bin/bash
### BEGIN INIT INFO
# Provides: killswitch
# Required-Start: openvpn $network $remote_fs $syslog
# Required-Stop: openvpn $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: VPN Killswitch
# Description: This script uses UFW to ensure all traffic goes through VPN
@twkm
twkm / backup.sh
Last active April 9, 2018 03:49
Duplicity Backups Script
#!/bin/bash
# Text enclosed in {} throughout should be replaced with your desired values
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# May also need to export $HOME: <https://bugs.launchpad.net/duplicity/+bug/758077>
# This seems to be necessary on a Mac crontab process
ulimit -n 4096
if [ -r .last_backup ]; then
LAST_BACKUP=$(cat .last_backup)
else
Verifying my Blockstack ID is secured with the address 1DtaqCvaV2wQwU38UKBRiMySASS7tfR9nB https://explorer.blockstack.org/address/1DtaqCvaV2wQwU38UKBRiMySASS7tfR9nB