Skip to content

Instantly share code, notes, and snippets.

View kyrathasoft's full-sized avatar

William.Miller kyrathasoft

View GitHub Profile
@kyrathasoft
kyrathasoft / MyFiles.cs
Last active August 29, 2015 14:02
Demonstrates: (1) converting file size (number of bytes) to string description, e.g., "7.405 Kb" (2) reading a file into an array of type byte (3) writing string data to a filepath (4) returning number of files in given directory matching a given pattern (5) returning total size of those pattern-matched files, in bytes (6) obtaining the director…
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using com.williambryanmiller.strings;
using com.williambryanmiller.testing;
namespace com.williambryanmiller.files {
class MyFiles {
@kyrathasoft
kyrathasoft / MyForms.cs
Created June 2, 2014 11:35
Four methods in static class MyForms.cs (1) center and size a form (2) center a control on a form (3) center a control horizontally only on a form (4) change the font and font style of a control
using System;
using System.Drawing;
using System.Windows.Forms;
namespace com.williambryanmiller.forms {
class MyForms {
public static void centerAndSizeForm(Form f, int frm_width, int frm_height) {
@kyrathasoft
kyrathasoft / MyStrings.cs
Last active August 29, 2015 14:02
Methods related to string manip in C#
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using com.williambryanmiller.testing;
using com.williambryanmiller.files;
namespace com.williambryanmiller.strings {
class MyStrings {
@kyrathasoft
kyrathasoft / TimeFormatting.cs
Created June 2, 2014 11:46
Takes total elapsed milliseconds and returns a string description of the elapsed time, such as "593 milliseconds, or 4.203 seconds, or 5.111 minutes".
using System;
namespace com.williambryanmiller.time {
class TimeFormatting {
public static string getDurationDesc(double numMilliseconds) {
const double Minute = 60000;
const double Second = 1000;
@kyrathasoft
kyrathasoft / MyTests.cs
Last active August 29, 2015 14:02
MyTests.cs has a bunch of boolean methods that test various conditions, returning true or false.
using System;
using System.Text.RegularExpressions;
namespace com.williambryanmiller.testing {
public static class MyTests {
public const string MatchEmailPattern =
@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
@kyrathasoft
kyrathasoft / ConsoleFormatting.cs
Last active August 29, 2015 14:02
ConsoleFormatting.cs has 7 methods for formatting output in C# Console applications.
using System;
namespace com.williambryanmiller.formatting {
public static class ConsoleFormatting {
/* Note: this code is also available on GitHub Gist @
https://gist.github.com/kyrathasoft/2292a9719517246786af */
public static void nThenPrint(int leadingSpaces, string str) {
@kyrathasoft
kyrathasoft / aboutDlg
Created June 16, 2014 12:43
about Dlg
namespace Kyrathasoft.Dialogs.About {
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
class clsAbout {
@kyrathasoft
kyrathasoft / iMapX
Created June 17, 2014 02:02
Send GMail via ImapX.dll
/* Required for this example:
*
* a C# WinForms application
* add reference to ImapX.dll available here:
* http://hellowebapps.com/wp-content/uploads/2010/07/ImapX_1.2.3.126.zip
* http://dl.dropbox.com/u/12124382/ImapX.zip
* a button <button1>
* a textbox <textBox1>
*
* Notes: I used a very specific Subject line as my search criteria, but you need not do this. You could
@kyrathasoft
kyrathasoft / stopwatch.txt
Last active July 21, 2018 00:08
stopwatch
class AutoStopwatchDemo : System.Diagnostics.Stopwatch, IDisposable
{
public AutoStopwatchDemo()
{
Start();
}
public void Dispose()
{
Stop();
Console.WriteLine(“Elapsed : {0}”, this.Elapsed);
@kyrathasoft
kyrathasoft / tester1.cs
Last active July 21, 2018 17:14
Tests if integer, if date, has some date manipulation methods. The helper methods in class Tester were developed as part of lessons associated with the following online tutorial series: http://williammillerservices.com/windows-c-console-programming/
using System;
/* a helper class, Tester, begun in Lesson 5 of intro C# console
programming series found at the following URL:
http://williammillerservices.com/windows-c-console-programming/
note: to use, you would reference the file containing this code
from your primary program file. If you have the following program...
GitHub gist -> https://gist.github.com/kyrathasoft/35357f7fee1c427693323286111e5e43
Pastebin.com -> https://pastebin.com/edit/K6D01kgv
using System;