Skip to content

Instantly share code, notes, and snippets.

View davej's full-sized avatar
💭
Working on @ToDesktop

Dave Jeffery davej

💭
Working on @ToDesktop
View GitHub Profile
@davej
davej / getS3CredentialsFromCloudflareToken.sh
Created February 15, 2025 20:58
Get S3 Credentials From Cloudflare Token
# Specify these vars first
export CLOUDFLARE_ACCOUNT_ID=24bac...
export CLOUDFLARE_API_TOKEN=eGCxnU...
# then derive the AWS S3 credentials
export AWS_ACCESS_KEY_ID=$(curl -s https://api.cloudflare.com/client/v4/user/tokens/verify -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq -r '.result.id')
export AWS_SECRET_ACCESS_KEY=$(echo -n $CLOUDFLARE_API_TOKEN | shasum -a 256 | awk '{print $1}')
export AWS_ENDPOINT_URL=https://$CLOUDFLARE_ACCOUNT_ID.r2.cloudflarestorage.com
# output the credentials
@davej
davej / main.js
Created October 11, 2022 17:21
Electron tray bounds bug on Mac
const { app, BrowserWindow, nativeImage, Tray } = require('electron')
let tray
function createTray() {
tray = new Tray(nativeImage.createEmpty())
// ❌ Doesn't work
console.log('sync', tray.getBounds())
@davej
davej / API.md
Created April 22, 2020 13:19
Config for todesktop.json

Project configuration (todesktop.json)

This describes all of the possible configuration options ín your todesktop.json.

To avoid confusion, the following terms will be used throughout this file:

  • "Project root": this is the parent directory of your todesktop.json.

appId - (optional) string

Keybase proof

I hereby claim:

  • I am davej on github.
  • I am davej (https://keybase.io/davej) on keybase.
  • I have a public key ASCGM6pZ2DMI-QNgpHyOlpPARpMxaK5PQI2eJIkwfMxiwwo

To claim this, I am signing this object:

@davej
davej / finished-polyfill.js
Last active August 29, 2019 14:14 — forked from simevidas/finished-polyfill.js
Animation.prototype.finished polyfill
// only polyfill .finished in browsers that already support animate()
if (document.body.animate) {
// Chrome does not seem to expose the Animation constructor globally
if (typeof Animation === 'undefined') {
window.Animation = document.body.animate({}).constructor;
}
if (!('finished' in Animation.prototype)) {
Object.defineProperty(Animation.prototype, 'finished', {
@davej
davej / prevent-idle.py
Created December 23, 2017 02:14
Prevent Mid 2014 MBP random shutdown
# From https://discussions.apple.com/thread/8115237
from time import sleep
while True:
sleep(0.00002)
@davej
davej / isLocalhost.js
Created April 9, 2017 11:42
Detect if current hostname is local
const isLocalhostName = window.location.hostname === 'localhost';
const isLocalhostIPv6 = window.location.hostname === '[::1]';
const isLocalhostIPv4 = window.location.hostname.match(
// 127.0.0.1/8
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
);
const isLocalhost = isLocalhostName || isLocalhostIPv6 || isLocalhostIPv4;
@davej
davej / fetch-timeout.js
Last active July 1, 2022 23:35
Add a pseudo timeout/deadline to a request using the ES6 fetch api
Promise.race([
fetch('/foo'),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 7000)
)
]);
@davej
davej / onScrollYChange.js
Last active September 12, 2016 21:04
Performant scroll change listener
// Your scroll callback will only be called once per frame and only
// when the y-position changes. Good for doing DOM work without causing
// unnecessary reflows of the document.
function onScrollYChange(callback) {
let latestKnownScrollY = 0, ticking = false;
const scrollChanged = () => {
ticking = false;
const currentScrollY = latestKnownScrollY;
callback(currentScrollY)
@davej
davej / optionDefaults.js
Last active July 25, 2016 12:15
Options object merged with defaults in ES2015+
function createSite(name, assignedOptions = {}) {
const defaultOptions = {
html: 'jade',
styles: 'scss',
scripts: 'babel',
whitespace: '2 spaces',
};
const options = Object.assign({}, defaultOptions, assignedOptions);
/*