Skip to content

Instantly share code, notes, and snippets.

View lawrencekgrant's full-sized avatar

Lawrence Grant lawrencekgrant

View GitHub Profile
@lawrencekgrant
lawrencekgrant / Program.cs
Last active October 3, 2018 13:12 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@lawrencekgrant
lawrencekgrant / list_of_types_to_csv.cs
Created September 19, 2012 00:42
List of types to CSV (without headers)
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace deflect
{
class Wizard
{
public string Name {get;set;}
@lawrencekgrant
lawrencekgrant / gist:1112964
Created July 29, 2011 01:40
Simply hash a file in C#
using System.IO;
using System.Security.Cryptography;
//Example: Hash("myfile.txt", "SHA-512");
public string Hash(string inputFile, string algorithm)
{
HashAlgorithm hash = HashAlgorithm.Create (algorithm);
FileStream fileStream = File.OpenRead (inputFile);
byte[] hashBytes = hash.ComputeHash (fileStream);
return Convert.ToBase64String (hashBytes);
@lawrencekgrant
lawrencekgrant / gist:1074168
Created July 10, 2011 02:14
Compress to tar.gz
private void CreateTarGZ (string tgzFilename, string sourceDirectory)
{
Stream outStream = File.Create (tgzFilename);
Stream gzoStream = new GZipOutputStream (outStream);
TarArchive tarArchive = TarArchive.CreateOutputTarArchive (gzoStream);
// Note that the RootPath is currently case sensitive and must be forward slashes e.g. "c:/temp"
// and must not end with a slash, otherwise cuts off first char of filename