Skip to content

Instantly share code, notes, and snippets.

View rfletcher's full-sized avatar

Rick Fletcher rfletcher

View GitHub Profile
/**
* A CloudFlare Worker which proxies an RSS feed, ensuring all <link/> values are secure URLs.
*
* Note: Works for my use case, but this needs more error checking before using widely.
*
* Usage: https://<yourworker>.workers.dev/https://example.com/feed.rss
*/
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
@rfletcher
rfletcher / app.js
Last active June 28, 2022 13:55
A simple bridge between iMessage and Home Assistant's conversation component
const HomeAssistant = require( 'homeassistant' );
const Pino = require( 'pino' );
const config = require( 'config' );
const hass = new HomeAssistant( config.get( 'home_assistant' ) );
const imessage = require( 'osa-imessage' );
const logger = Pino();
// TODO package this better
const bridge = {
@rfletcher
rfletcher / lastfm-dedupe.js
Created February 16, 2016 14:39
Bookmarklet to remove duplicates from your Last.FM track list
/**
* Bookmarklet to remove duplicate entries from your Last.FM track list.
*
* Bookmarklet version:
* javascript:(%20function()%20{var%20row_to_title%20=%20function(%20$tr%20)%20{return%20$tr.find(%20%22.chartlist-name%20a:not(:empty)[title*=%E2%80%94]%22%20).attr(%20%22title%22%20).replace(%20/\s+/g,%20%27%20%27%20);};jQuery(%20%22table.chartlist%20>%20tbody%20>%20tr%22%20).each(%20function()%20{var%20$tr%20=%20jQuery(%20this%20),$siblings%20=%20jQuery(%20$tr.nextAll(%20%22tr%22%20).slice(%200,%206%20)%20),current_title%20=%20row_to_title(%20$tr%20);$siblings.each(%20function()%20{var%20$sibling%20=%20jQuery(%20this%20),sibling_title%20=%20row_to_title(%20$sibling%20);if(%20sibling_title%20!==%20%22%22%20&&%20current_title%20===%20sibling_title%20)%20{console.log(%20%22Removed%20%22%20+%20sibling_title%20);$sibling.find(%20%22.chartlist-delete%20form%20[type=submit]%22%20).click();return%20false;}});}%20);}()%20);
*
* Full version:
*/
( function() {
var row_to_title = function( $tr ) {
@rfletcher
rfletcher / FCPrivateBatteryStatus.m
Created January 30, 2016 01:31
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);
@rfletcher
rfletcher / az.bash
Last active May 2, 2019 12:49
List all AWS availability zones
#!/usr/bin/env bash
# List all AWS availability zones
#
# Depends on:
# - `aws`: https://aws.amazon.com/cli/ (installed and configured with credentials)
# - `jq`: https://stedolan.github.io/jq/
#
for REGION in $(
aws ec2 describe-regions | jq --raw-output '.Regions | map(.RegionName) | .[]' | sort

Keybase proof

I hereby claim:

  • I am rfletcher on github.
  • I am fletch (https://keybase.io/fletch) on keybase.
  • I have a public key whose fingerprint is 3F1A 6410 49F5 8FFA FB75 3962 8013 507D 62FF 7CF0

To claim this, I am signing this object:

@rfletcher
rfletcher / jquery.browser.js
Created February 12, 2013 22:24
Include this jQuery plugin to restore the jQuery.browser API, removed in 1.9.0. Useful if you have dependencies that still require it, like the popular jQuery BBQ plugin.
// Restore the removed jQuery.browser API to satisfy dependencies.
//
// Copied and pasted from the jQuery 1.8.3 source:
// http://code.jquery.com/jquery-1.8.3.js
( function( jQuery ) {
var matched, browser;
// Use of jQuery.browser is frowned upon.
// More details: http://api.jquery.com/jQuery.browser
@rfletcher
rfletcher / file.js
Created August 3, 2011 18:47
Simple build-time javascript dependency resolution
( function() {
console.log( 'one' );
//= require two.js
}() );
# wait for a remote server to start up
function wait_for_server() {
echo -n "waiting for server to start"
for i in {1..10};
do
nc "$1" "$2" < /dev/null && echo && return 0;
echo -n "."
sleep 1
done
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes