Skip to content

Instantly share code, notes, and snippets.

View RupW's full-sized avatar

Rupert Wood RupW

View GitHub Profile
@RupW
RupW / cryptoJsCompatibleAes.ts
Last active December 13, 2023 14:02
CryptoJS-compatible AES encrypt and decrypt with password / pre-shared secret using Node built-in crypto instead
import * as crypto from 'node:crypto';
// Format is "Salted__", 8-byte salt, cipher text
const saltedPrefixBuffer = Buffer.from('Salted__');
function md5(...inputs: Buffer[]): Buffer {
const hash = crypto.createHash('md5');
inputs.forEach(input => hash.update(input));
return hash.digest();
}
@RupW
RupW / svg-text-anchor-middle.html
Last active July 22, 2022 16:32
Examples of SVG text rendering differences on Safari
<!DOCTYPE html>
<html lang="en-US">
<head><title>Safari textpath multiple tspans text-anchor:middle</title>
<style>
body {
height: 100%;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.42857143;
// https://stackoverflow.com/q/59054704/243245
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class BinarySearchExample {
public static void main( String[] args )
throws IOException
@RupW
RupW / SO46289473.java
Created September 21, 2017 00:58
Solve W=C tan W using Newton-Raphson - for https://stackoverflow.com/q/46289473
/**
* A Newton-Raphson implementation of https://stackoverflow.com/q/46289473
*/
public class SO46289473
{
public static double nrSolveW(double c, double epsilon) {
double guessValue;
if (c < 0 && c != Double.NEGATIVE_INFINITY) {
// Then 1st intersection is between π/2 and π (towards -infinite C)
guessValue = Math.PI * 0.75;
@RupW
RupW / functions.php
Last active August 29, 2015 14:05
WordPress theme snippet to warn if no permalink structure configured
<?php
/**
* "We strongly recommend a permalink structure" admin site notice
*
* from http://wordpress.stackexchange.com/a/157071/3276
*/
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
/* Admin-site only code */
@RupW
RupW / jquery.support.checkboxindeterminate.js
Created April 6, 2012 09:35
Detect HTML5 checkbox indeterminate support storing result in jQuery.support namespace
/**
* jQuery.support.checkboxIndeterminate
* https://github.com/RupW
* Tests for HTML 5 checkbox 'indeterminate' property
* http://www.w3.org/TR/html5/the-input-element.html#dom-input-indeterminate
* http://www.w3.org/TR/html5/number-state.html#checkbox-state
*
* Released under the same license as jQuery
* http://docs.jquery.com/License
*