Skip to content

Instantly share code, notes, and snippets.

View philronan's full-sized avatar

Phil Ronan philronan

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sudoku cheat</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Mono&display=swap" rel="stylesheet">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@philronan
philronan / wgs84LatLon2Osgb36EastNorth.c
Created February 12, 2023 12:06
Convert WGS84 latitude/longitude coordinates into OSGB36 easting/northing coordinates (as used in OS maps and gov.uk web sites)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Convert Latitude and Longitude to Easting and Northing coordinates
// Distilled from Visual Basic code published by the Ordnance Survey.
// Constants
#define DEG2RAD (M_PI / 180)
#define OSGB36_A 6377563.396 // OSGB36 semi-major & semi-minor axis
@philronan
philronan / rsa-pq-xor-crack.py
Last active April 19, 2021 14:21
Determine the factors p and q of an RSA modulus n (=p×q) given the values of n and p XOR q
# Given a semiprime n and the xor product of
# its two factors p and q, calculate p and q
def rsa_xor_crack(n, pxq, k, start, p0):
# n: the semiprime we are trying to factorize (=p*q)
# pxq: the XOR product of n's two prime factors (= p^q)
# k: the number of bits to extract per iteration
# start: the first unknown bit we want to find
# p0: a tentative value for the first start bits of p
bit_mask = (1 << start + k) - 1
@philronan
philronan / ScoreKeeper.cs
Created December 13, 2019 00:18
Unity scorekeeper with secret token mechanism to make it harder to falsify scores
/**
*
* NOTE: I created this script to make it harder to falsify scores in Unity
* WebGL games. It's designed to sit between the objects that modify scores
* and the object(s) that display them to the user. If an object needs to
* modify the score, then (a) add this object to the scoreSetters[] aray,
* and (b) add the method `public void SetSharedSecret(ulong secret)` to
* receive and store a 64-bit secret value (guaranteed to be non-zero). For
* example:
*
@philronan
philronan / Unity2D_Arkanoid_Bounce.cs
Last active December 13, 2019 00:20
Arkanoid style games get rather boring in Unity 2D physics if the ball ends up stuck in a horizontal or vertical bounce loop. Here's a quick fix:
[Range(7.0f,15.0f)] [SerializeField] float pushSpeed = 12.0f;
[Range(0.2f, 0.9f)] [SerializeField] float bounceFudge = 0.4f;
private void OnCollisionExit2D(Collision2D collision)
{
// Prevent ball from following paths that are too close to horizontal
// or vertical (to prevent boring loops)
// Get the ball's velocity (after a bounce)
Vector2 ballVector = myRigidBody2D.velocity;
@philronan
philronan / himawari-grabber.sh
Created September 28, 2018 09:24
Grab images of Earth from the Himawari-8 satellite
#!/bin/bash
# Fetch full-resolution Earth images from the Himawari-8 satellite
# Requires ImageMagick, curl, Perl
# The URL structure of the image server is liable to change, but currently looks like this:
# Typical url = https://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/YYYY/MM/DD/hhmm00_XX_YY.png
# YYYY/MM/DD = date
# hhmm = UTC time (rounded to 10 minutes)
# XX, YY = X and Y coordinates of tile (0 <= XX, YY <= 19)
@philronan
philronan / sha256_proof_of_work.c
Created June 12, 2018 11:10
A proof of work function based on SHA256 hashes; finds a string with a given prefix whose hash value ends in the required number of zero bits
/* compile with: cc -Wall -O3 sha256_proof_of_work.c -o sha256_proof_of_work -lcrypto */
#include <openssl/sha.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define PREFIX_BYTES 16
#define MAX_HASH_ATTEMPTS 10000000000L
@philronan
philronan / ppt-font-change.scpt
Last active June 10, 2018 13:54
Change the font of all text boxes in a Powerpoint presentation
tell application "Microsoft PowerPoint"
tell active presentation
set theSlideCount to count slides
repeat with a from 1 to theSlideCount
set numShapes to count shapes in slide a
repeat with b from 1 to numShapes
set sh to (shape b of slide a)
if has text frame of sh then
set f to font of text range of text frame of sh
set font name of f to "Arial"