Skip to content

Instantly share code, notes, and snippets.

@jcward
jcward / cleanup_github_known_hosts.rb
Created March 27, 2023 18:30
Remove github IP addresses from known_hosts
#!/usr/bin/env ruby
#
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
# https://stackoverflow.com/questions/75830783
#
# Scan for github IP addresses in your knwon_hosts and remove them
# - Takes ~1.5 minutes on my machine
# - Skips the huge "actions" IP ranges
# - Skips IPv6
@jcward
jcward / web_timer.js
Created February 13, 2023 16:41
Put a timer in the corner of nearly any webpage
// Click to (re)start, shift-click to increment, ctrl-click to decrement
// Customize the initial time (currently 60 seconds), size, and position
// Copy-paste into dev tools (CTRL-SHIFT-i)
(function() {
var init_time = 60, size = 1.5, position = "top right";
var t = init_time;
var e = document.createElement('div');
e.style.position = "fixed";
position = position.split(" ");
@jcward
jcward / Client.hx
Last active January 17, 2024 04:04
A Quick Haxe Client / Server Socket Example
import sys.net.Host;
import sys.net.Socket;
class Client
{
public function new()
{
var args = Sys.args();
if (args.length==0) {
trace('Usage: Client <server ip / hostname>');
@jcward
jcward / _README.md
Last active July 23, 2021 18:50
Inline a source map file into the JavaScript source file as a data URI

Description:

A quick script to inline / inject a source map file into the JavaScript source file.

Use case: Sometimes you have a script.js and a script.js.map file, and you'd prefer to inline the source map as a data URI directly into the script.js file.

NOTE: Modifies the script.js file in-place

@jcward
jcward / mem_freeze_monitor.py
Created January 6, 2020 19:49
Memory monitor python script, kills highest-using process at threshold
#!/usr/bin/env python3
# Memory monitor script. Starts killing highest-mem-usage processes
# (e.g. usually chrome tabs) when RAM exceeds some threshold (e.g. 92%).
# When running without swap, this helps to avoid freezes.
#
# Source: https://askubuntu.com/a/1018733/159633
#
# Run with sudo
@jcward
jcward / astar_pathfinding.md
Last active December 6, 2023 06:12
A cached copy of Patrick Lester's A* Pathfinding for Beginners

Retrieved from web.archive.org (link)

Originally available from http://www.policyalmanac.org/games/aStarTutorial.htm (link defunct)

A* Pathfinding for Beginners

By Patrick Lester (Updated July 18, 2005)

This article has been translated into Albanian, Chinese, Finnish, German, Greek, Korean, Polish, Portuguese, Romanian, Russian, Serbian, and Spanish. Other translations are welcome. See email address at the bottom of this article.

@jcward
jcward / check_lid.rb
Created October 3, 2019 05:31
Quick script to check the laptop lid state (Surface Pro 3, Ubuntu 18.04), and trigger hibernate
#!/usr/bin/env ruby
#
# Disable lid control in /etc/systemd/logind.conf, for example:
#
# [Login]
# HandlePowerKey=hibernate
# HandleSuspendKey=ignore
# HandleLidSwitch=ignore
cnt = 0
@jcward
jcward / server.c
Last active August 9, 2019 20:00
A C socket server that runs a command and returns the response, socket input is ignored
// A simple C socket server cobbled of examples that runs a command
// and returns the response over the socket, socket input is ignored.
// MIT LICENSE / NO WARRANTY OR GUARANTEE OF FITNESS FOR ANY PURPOSE
// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
// Please note and fill in the defines below
// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
#define CMD "date" // The command to run
@jcward
jcward / test_certs.rb
Created July 10, 2019 14:42
CI test for SSL certificate expiration
#!/usr/bin/env ruby
#
# Checks each server's certificate, and fails (exit 1) if it is etiher
# unreachable, or the certificate expires within 7 days.
require 'time'
min_days_left = 7
servers = [
"one.example.com",
@jcward
jcward / Test.hx
Created July 31, 2018 23:30
TypedefMacro.hx - Haxe macro to get typedef fields at macro-time
class Test {
static function main() {
trace("Haxe is great!");
var fields = TypedefMacro.fieldNames(Something);
trace(fields);
var fields_with_opt = TypedefMacro.fieldNames(Something, true);
trace(fields_with_opt);
}