Skip to content

Instantly share code, notes, and snippets.

View pmachapman's full-sized avatar

Peter Chapman pmachapman

View GitHub Profile
@pmachapman
pmachapman / smallcaps.cs
Created June 24, 2023 07:45
Small Caps Generator
using System;
using System.Text;
Console.WriteLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Console.WriteLine(SmallCaps("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
/// <summary>
/// Gets a the first match in capital letters as small caps.
/// </summary>
/// <param name="text">The text.</param>
@pmachapman
pmachapman / parse-creeds-json.ps1
Created February 8, 2022 01:35
Parses a JSON file from Creeds.json into HTML
$url = "https://raw.githubusercontent.com/NonlinearFruit/Creeds.json/master/creeds/keachs_catechism.json"
$parts = $url.Split("/")
$index = $parts.count - 1
$filename = $parts.GetValue($index).ToString().Replace("_", "-").Replace(".json", ".html")
$response = Invoke-WebRequest -Uri $url -UseBasicParsing
$creed = $response | ConvertFrom-Json
foreach ($data in $creed.data)
{
"<li id=`"q$($data.Number)`">" | Out-File -FilePath $filename -Append
$question = $data.Question.Replace("'", "&rsquo;")
@pmachapman
pmachapman / string_literal.vbs
Created February 2, 2022 02:19
Drag and drop a file onto this script to create a text file containing the escape codes to use in a C++ string literal
Const ForWriting = 2
data = ""
fileName = WScript.Arguments.Item(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(fileName)
Do Until f.AtEndOfStream
buf = f.Read(1)
data = data & "\x" & Hex(Asc(buf))
Loop
f.Close
@pmachapman
pmachapman / sort.php
Last active February 8, 2022 01:34
A PHP Script to sort Scripture references.
<?php
/*
* Roughly sorts a list of scripture references in the following format:
* Ezekiel 8:5-18; Psalm 44:20-21; 1 Chronicles 28:9;
*
* I'm not proud of this script, and there is no real bounds or value checking. Recycle this code at your own risk!
*/
$books = array(
'Genesis',
'Exodus',
@pmachapman
pmachapman / settings.json
Created October 30, 2020 22:03
Windows Terminal Settings
// This file was initially generated by Windows Terminal 1.3.2651.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@pmachapman
pmachapman / LinkifyTextView.cs
Last active June 19, 2019 02:58
A Xamarin Android TextView that supports Linkify and gestures
// -----------------------------------------------------------------------
// <copyright file="LinkifyTextView.cs" company="Conglomo">
// Copyright 2019 Peter Chapman. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Conglomo.AndroidSupport
{
using Android.Content;
using Android.Runtime;
@pmachapman
pmachapman / EncodeCsvField.cs
Created November 5, 2018 03:58
Encode a field for a CSV file
/// <summary>
/// StringUtilities class
/// </summary>
public static class StringUtilities
{
/// <summary>
/// Encodes a string for a CSV field.
/// </summary>
/// <param name="field">The field to encode.</param>
/// <param name="separator">The separator (defaults to a comma).</param>
@pmachapman
pmachapman / GetForwardedIp.aspx
Created May 4, 2018 03:35
A simple test script to get what the forwarded IP address is
<% @Page Language="C#" %>
<%
Response.Write("'" + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(',')[0] + "'");
%>
@pmachapman
pmachapman / Spectre Registry Check.bat
Created February 16, 2018 19:46
Spectre/Meltdown Compatibility Registry Check
@echo off
cls
rem Spectre Compatibility Registry Check
rem By Peter Chapman <peter@conglomo.co.nz>
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat /v cadca5fe-87d3-4b96-b7fb-a231484277cc
if %ERRORLEVEL% EQU 0 goto :exists
color 4
echo FAIL: Registry Key Not Present
goto :end
:exists
@pmachapman
pmachapman / genrandom.c
Created July 11, 2017 21:46
A simple example for CryptGenRandom
#include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
int main(int argc, char *argv[])
{
/* Declare variables */
HCRYPTPROV hCryptProv;
BYTE pbData[16];