Skip to content

Instantly share code, notes, and snippets.

View jaygooby's full-sized avatar
✏️
working on https://writiny.com in my sparse spare time

Jay Caines-Gooby jaygooby

✏️
working on https://writiny.com in my sparse spare time
View GitHub Profile

If you import live data into Google Docs spreadsheets using the importdata function and you want to force a refresh at a certain interval, but you also want to ensure that some cache-busting goes on, append a querystring that's the epoch time value that the refresh occurs, so for a sheet that should grab new data every hour you could force an update like this:

importData("http://example.com/data.csv?" & hour(googleclock()) & ")")

But the url requested looks like this: http://example.com/data.csv?11 if the refresh happened at 11am. The next day at 11, the url will be the same, so there's a chance you may get cached data. To get around this, use an epoch time-based refresh. The formula:

=((date(year(googleclock()),month(googleclock()),day(googleclock())) & " " & time(hour(googleclock()), 0, 0)) - DATE( 1970;1;1))*86400

gives you the epoch timestamp for the time at the current hour. If you wanted the timest

@jaygooby
jaygooby / src-hilite-lesspipe.sh
Last active February 21, 2024 08:37
A modified version of gnu source-highlight's src-hilite-lesspipe.sh that also works with piped files and files with no extensions. It uses the file command to guess the language. This means you can use source-highlight in conjunction with commands like "git show"
#! /bin/bash
#
# Based on http://git.savannah.gnu.org/cgit/src-highlite.git/tree/src/src-hilite-lesspipe.sh.in
# by Lorenzo Bettini
#
# Modified by Jay Caines-Gooby to support piped files
# jay@gooby.org
# @jaygooby
#
# Typically called by setting:
# DOH. There's a command for this already:
ssh-keygen -R <the host>
@jaygooby
jaygooby / git_notes.md
Last active October 16, 2023 16:26
Git, you bloody git

Overwrite untracked files in current branch from a remote branch

In a similar vein to git reset --hard feature/weavils you can just overwrite untracked working files (typically left over from branch experiments) which are part of the remote branch you're pulling like this:

git reset --hard origin/feature/weavils

Normally, if you tried git checkout feature/weavils you'd get warnings like untracked working tree files would be overwritten by merge, so hit them with the --hard hammer instead.

(Found via https://stackoverflow.com/q/17404316/391826 and one of the answers: https://stackoverflow.com/a/36824493/391826)

@jaygooby
jaygooby / bluetooth-device-toggle.applescript
Created August 8, 2023 10:47
Toggle your Nothing ear (1) as the active bluetooth device
# Totally stolen from
# https://gist.github.com/ieatfood/814b065964492f71f728da59a47413bc
#
# Export this applescript as an app, and then just double click to toggle on & off
use framework "IOBluetooth"
use scripting additions
set blueToothDevice to "Nothing ear (1)"
@jaygooby
jaygooby / nginx-google-domain-csp-map.sh
Created February 6, 2020 15:30
Use the correct google country domain in your nginx content-security-policy header, instead of all of them
#!/bin/bash
#
# Generates an nginx compatible map that you can use to
# put the relevant Google country code in your Content-Security-Policy
# instead of having them all.
#
# Add these to your nginx config:
# geoip2 /path/to/GeoLite2-Country.mmdb {
# $geoip2_country_code default=US source=$remote_addr country iso_code;
# $geoip2_country_name country names en;
@jaygooby
jaygooby / double-dropbox.sh
Created February 13, 2014 16:20
Starts Dropbox and Dropbox Encore for OS X in the correct order. Add to your Login Items in System Preferences
#!/bin/bash
#
# To run Dropbox and Dropbox Encore[1] together, you've
# got to start Dropbox first. I *always* forget this,
# so added this script to my Login Items instead
#
# [1] http://www.joyofmacs.com/software/dropboxencore/
#
# Jay Caines-Gooby
# jay@gooby.org
@jaygooby
jaygooby / netblock-from-whois
Last active April 16, 2023 11:08
Gets and caches the netblock owner from `whois` for an IP address
#!/bin/bash
#
#
# MIT License
#
# Copyright (c) 2022 Jay Caines-Gooby, @jaygooby, jay@gooby.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@jaygooby
jaygooby / interesting-referers
Last active November 22, 2022 14:52
Find interesting referers in access.log - see https://jay.gooby.org/2021/11/30/find-interesting-referers-in-access-log for more details
#!/bin/bash
#
# MIT License
#
# Copyright (c) 2021 Jay Caines-Gooby, @jaygooby, jay@gooby.org
#
# The one-liner from https://jay.gooby.org/2021/11/30/find-interesting-referers-in-access-log
#
# Usage: interesting-referers /path/to/access.log
# interesting-referers /path/to/access.log example.com
@jaygooby
jaygooby / percona-xtrabackup.sh
Last active May 9, 2022 15:43
Call via crontab on whatever schedule suits you; keep n full mysql Percona xtrabackups of your mysql database, with binary logs applied. Also does a full mysqldump that can then have the binary logs applied to restore to a point-in-time backup via the binlogs. Copy all of this (backup, mysqldump, binlogs) to S3.
#!/bin/bash
#
# Carries out a full mysqldump, calls percona-xtrabackup and then
# copies the sql dump, the percona backup and your mysql bin logs
# to S3 using s3cmd http://s3tools.org/s3cmd
#
# TODO: extract out the S3 backup stuff to make it optional, and so
# other s3 programs can replace the s3cmd call.
# TODO: the if [ $? == 0 ] alert blocks should be a function
# TODO: make the if [ $? == 0 ] if [ $? != 0 ] more consistent - test