Skip to content

Instantly share code, notes, and snippets.

View kyrathasoft's full-sized avatar

William.Miller kyrathasoft

View GitHub Profile
@kyrathasoft
kyrathasoft / gethash.cs
Last active May 18, 2021 13:28
Library for returning SHA1 and MD5 hashes
/* This code was copied by Bryan Miller 16th May 2021, but the actual prime detection
methods contain code found on various websites and forums. */
using System;
using System.Security.Cryptography;
using System.Text;
namespace GetHashNs {
public class GetHashCls {
using System;
using GetHashNs; //found in gethash.cs
namespace SnippetNamespace {
public class SnippetClass {
static void Main(string[] args){
string p = "Bryan Miller";
@kyrathasoft
kyrathasoft / prime.cs
Created May 16, 2021 13:36
an efficient method for detecting if a positive integer is a prime number
/* This code written by Bryan Miller 9th May 2021, but the actual prime detection
methods contain code found on various websites and forums.
To create DLL prime.dll, csc /t:library prime.cs
To build EXE myprogram.exe referencing that DLL, csc /r:prime.dll myprogram.cs */
using System;
namespace IsPrimeNs {
@kyrathasoft
kyrathasoft / cryptorandom.cs
Last active May 16, 2021 13:33
use this for random number generation
using System;
using System.Security.Cryptography;
using System.Diagnostics.CodeAnalysis;
namespace RandomNs
{
public class CryptoRandom : Random
{
private RNGCryptoServiceProvider _rng = new RNGCryptoServiceProvider();
@kyrathasoft
kyrathasoft / hashing methods
Created November 9, 2019 13:36
computer SHA1 and MD5 hashes of strings
//requires using System.Security.Cryptography;
static string GetSHA1 (string ipString) {
SHA1 sha1 = new SHA1CryptoServiceProvider ();
byte[] ipBytes = Encoding.Default.GetBytes (ipString.ToCharArray ());
byte[] opBytes = sha1.ComputeHash (ipBytes);
StringBuilder stringBuilder = new StringBuilder (40);
for (int i = 0; i < opBytes.Length; i++) {
stringBuilder.Append (opBytes[i].ToString ("x2"));
@kyrathasoft
kyrathasoft / moveFormWithoutTitlebar.cs
Created November 9, 2019 13:25
Move a form using MouseDown() even if it doesn't have a titlebar
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
/*
Shows how to move the form without using a Title Bar to drag the form around the screen.
This can be adapted for custom forms (those with a customized picture box image overlaying the form,
and FormBorderstyle set to 'None' by simply changing Form1_MouseDown() to pictureBox1_MouseDown()...
*/
@kyrathasoft
kyrathasoft / txtbox_modify
Created November 9, 2019 13:14
Access and modify properties of textbox from within another class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/*
@kyrathasoft
kyrathasoft / count_entries.php
Last active October 21, 2019 00:49
code to count # of Flatpress blog entries made
<!DOCTYPE html>
<html>
<head>
<title>Blog Entries Counter</title>
</head>
<body>
<?php
$path = realpath('fp-content/content');
$regular_entries = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
@kyrathasoft
kyrathasoft / count.cs
Created October 10, 2019 02:02
demonstrates counting number of words in a string
using System;
namespace Example {
class Program {
static void Main(string[] args){
string p = "This is a brief sample sentence.";
string[] words = p.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(" The following sentence contains {0} words:", words.Length);
@kyrathasoft
kyrathasoft / get the names of top-level subdirectories
Last active October 3, 2019 21:14
String array containing top-level subdirectories
/* shows how to get a string array holding the names of all top-level subdirectories
online at:
https://gist.github.com/kyrathasoft/1dc1a1eb4d6a2a56827dcb5f43840afe
To compile: csc *.cs
Here is the structure of this example program
and associated directories, on disk: