Skip to content

Instantly share code, notes, and snippets.

View grandsilence's full-sized avatar
💻
Freelancer

Grand Silence grandsilence

💻
Freelancer
View GitHub Profile
@kristopherjohnson
kristopherjohnson / ReadResourceFile.cs
Created August 1, 2012 17:53
C# snippet: Read embedded resource file
/// <summary>
/// Read contents of an embedded resource file
/// </summary>
private string ReadResourceFile(string filename)
{
var thisAssembly = Assembly.GetExecutingAssembly();
using (var stream = thisAssembly.GetManifestResourceStream(filename))
{
using (var reader = new StreamReader(stream))
{
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<PropertyChanged EventInvokerNames="NotifyOfPropertyChange" />
</Weavers>
@benhysell
benhysell / DatabaseCall.cs
Last active May 14, 2024 02:59
c# Redis Caching Objects with StackExchange.Redis using Json
//extension method make a database call by providing a function pointer to Task<T> and passing in a method parameter
public static async Task<T> DatabaseCall<T>(this IDatabase cache, string key, Func<string, Task<T>> databaseCall, string methodParameter, TimeSpan timeSpan, bool invalidate, bool useCache)
{
T returnValue;
var cachedItem = default(T);
try
{
cachedItem = await cache.GetAsync<T>(key);
}
catch (RedisConnectionException ex)
@carols10cents
carols10cents / c#-to-rust.md
Last active November 5, 2024 09:30
C# to Rust Cheat Sheet

Thanks to @seejee for making this for me!!!

C# to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables

@DanielSWolf
DanielSWolf / Program.cs
Last active March 21, 2025 16:29
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);
@richlander
richlander / dotnet-crypto-46.cs
Last active June 4, 2022 18:45
.NET Cryptography Updates for the .NET Framework 4.6
// Example 1: Signing a byte[] using PKCS#1 v1.5 padding and a SHA-256 hash
// 4.5:
public static byte[] SignDataPkcs1Sha256(X509Certificate2 cert, byte[] data)
{
// X509Certificate2.PrivateKey returns the same object across multiple calls,
// so it shouldn't be Disposed independent of the X509Certificate2 object.
//
// The RSA base class doesn't expose any signature-based methods.
// The PrivateKey property returns AsymmetricAlgorithm, so really this call should be
@ziadoz
ziadoz / composer_path.json
Last active August 14, 2024 07:56
Composer Using Local Repositories and Branches
{
"repositories": [
{
"type": "path",
"url": "../relative/project/path"
}
],
"require": {
"${project}": "dev-${branch}"
}
@dantheman213
dantheman213 / HttpGetRequestSync.cs
Created July 30, 2015 23:41
C# HTTP GET request synchronous example
using System.Net.Http;
using (var client = new HttpClient())
{
var url = "http://google.com/api-example";
var response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
// by calling .Result you are performing a synchronous call
@tenowg
tenowg / RedisJobQueue.cs
Last active December 21, 2024 10:34
A Message/Job Queue based on StackExchange.Redis and Redis Server
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using StackExchange.Redis;
namespace CitySurvival.Redis
{
@syed
syed / aes_cbc_pkcs5_b64.go
Last active December 12, 2022 10:11
This simple program is to demonstrate encryption and decryption in golang using AES CBC with PKCS5Padding
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
b64 "encoding/base64"
"errors"
"fmt"
"log"