Skip to content

Instantly share code, notes, and snippets.

View pmachapman's full-sized avatar

Peter Chapman pmachapman

View GitHub Profile
@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];
@pmachapman
pmachapman / tinybasic.c
Created March 23, 2016 09:54
A tiny BASIC Interpreter
/* A tiny BASIC interpreter */
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#define NUM_LAB 100
@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 / 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 / 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 / CDKey.c
Last active March 29, 2021 21:20
Microsoft CD Key Validation
/*
This source code contains a authentication routine that will
validate Microsoft CD Keys. It is meant that this source code
is a learning tool and not a PIRACY tool. It is also meant to
show how a large corporation like Microsoft spend MILLIONS of
dollars on development and come up with this protection scheme.
*BorlandC 3.1 was used to compile this successfully.
It is a crime to redistribute these routines in a commercial
@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 / msbin.c
Created September 26, 2016 07:24
Microsoft Binary Data Format Functions
//
// The following are implementations of Microsoft RTL functions not
// include in the Borland RTL.
//
// Functions:
// _fmsbintoieee()
// _fieeetomsbin()
// _dmsbintoieee()
// _dieeetomsbin()
//
@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;