Skip to content

Instantly share code, notes, and snippets.

Avatar

Cameron Sjo cameron-sjo

  • Bentonville, AR
View GitHub Profile
@cameron-sjo
cameron-sjo / RSAKeys.cs
Created Jul 3, 2019 — forked from ststeiger/RSAKeys.cs
Import and export RSA Keys between C# and PEM format using BouncyCastle
View RSAKeys.cs
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using System;
using System.IO;
using System.Security.Cryptography;
namespace MyProject.Data.Encryption
{
View gist:ca14ca4e64a8f389742d731feab8940a
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
View WeightedRandom.cs
var weights = new [] {
new {Desc = "A", Weight = 40},
new {Desc = "B", Weight = 25},
new {Desc = "B1", Weight = 20},
new {Desc = "C", Weight = 3},
new {Desc = "D", Weight = 1},
new {Desc = "E", Weight = 1},
new {Desc = "F", Weight = 10}
};
@cameron-sjo
cameron-sjo / JsonResult.cs
Last active Oct 31, 2016
Class for generating standardized JSON API responses in C#.
View JsonResult.cs
using Newtonsoft.Json;
/// <summary>
/// This is a slightly modified C# implementation of the JSON API format.
/// Documentation is available here: http://jsonapi.org/format/
/// </summary>
public class JsonResult
{
/// <summary>
View OneTimePasswordGenerator.cs
public static class Base32
{
public static byte[] ToBytes(string input)
{
if (string.IsNullOrEmpty(input))
{
throw new ArgumentNullException("input");
}
input = input.TrimEnd('='); //remove padding characters
View Get-ProjectReferences.ps1
# http://stackoverflow.com/a/10472358/2607840
Function Get-ProjectReferences ($rootFolder)
{
$projectFiles = Get-ChildItem $rootFolder -Filter *.csproj -Recurse
$ns = @{ defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/2003" }
$projectFiles | ForEach-Object {
$projectFile = $_ | Select-Object -ExpandProperty FullName
$projectName = $_ | Select-Object -ExpandProperty BaseName
$projectXml = [xml](Get-Content $projectFile)
@cameron-sjo
cameron-sjo / gist:06e435e298f6a873d8518cd4d1a64127
Created Aug 10, 2016 — forked from rarous/gist:3529050
Generate MetaProj file from solution
View gist:06e435e298f6a873d8518cd4d1a64127
$env:MSBuildEmitSolution=1
msbuild FooBar.sln /t:ValidateSolutionConfiguration
$env:MSBuildEmitSolution=0
View BatchWorkUsingBlockingCollections.cs
async Task Main()
{
var checkoutQueue = new System.Collections.Concurrent.BlockingCollection<string>(new ConcurrentQueue<string>());
var searchQueue = new System.Collections.Concurrent.BlockingCollection<string>(new ConcurrentQueue<string>());
var queues = new
{
Checkout = checkoutQueue,
Search = searchQueue
};
View PrettyPrintXml.cs
public static string PrettyPrintXml(this string xml)
{
using (var stream = new MemoryStream())
using (var writer = new XmlTextWriter(stream, Encoding.Unicode))
{
var document = new XmlDocument();
// Load the XmlDocument with the XML.
document.LoadXml(xml);
writer.Formatting = Formatting.Indented;
You can’t perform that action at this time.