Skip to content

Instantly share code, notes, and snippets.

@hongymagic
hongymagic / Interval.cs
Last active December 15, 2023 13:09
Representing Intervals in C# with Generics support `Interval<T>`
using System;
namespace Hongy
{
/// <summary>
/// Represents vectorless interval of the form [a, b] or (a, b) or any
/// combination of exclusive and inclusive end points.
/// </summary>
/// <typeparam name="T">Any comparent type</typeparam>
/// <remarks>
#install chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
#generate list of installed applications with exact version
choco list -lo -r -y | % { "choco install " + $_.Replace("|", " ") + " -y" }
#generate list of installed application without version.
choco list -lo --id-only -y | % { "choco install " + $_.Replace("|", " ") + " -y" }
@haeky
haeky / encryption.cs
Created June 17, 2013 14:34
Encrypt, decrypt and generate a key in C# using AES256.
#region Encryption
/// <summary>
/// Generate a private key
/// From : www.chapleau.info/blog/2011/01/06/usingsimplestringkeywithaes256encryptioninc.html
/// </summary>
private static string GenerateKey(int iKeySize)
{
RijndaelManaged aesEncryption = new RijndaelManaged();
aesEncryption.KeySize = iKeySize;
aesEncryption.BlockSize = 128;
@craigrbruce
craigrbruce / ApiClient.cs
Last active April 26, 2022 23:06
An example REST API client for C#
/*
Call the api client like this:
var client = new ApiClient<SEnvelope>("https://baseurl.com/api/v1");
//you would overload and add an auth_token param here
client.GetDtoAsync("envelopes", "object_id", (response) => //callback
{
this.SEnvelope = response.Data;//should be an envelope from the server
});
@drasticactions
drasticactions / jsonnet.workbook
Created March 16, 2017 17:13
JSON.NET Deserialize Example
uti platforms packages
com.xamarin.workbook
Console
id version
Newtonsoft.Json
9.0.1

JSON.NET Deserialize Example

#Requires -RunAsAdministrator
#Requires -Version 3.0
#References:
#Getting Started with Nano Server <https://technet.microsoft.com/en-us/library/mt126167.aspx>
#Quick Guide - Deploying Nano Server using PowerShell <http://deploymentresearch.com/Research/Post/479/Quick-Guide-Deploying-Nano-Server-using-PowerShell>
param (
#[ValidateScript({ Test-Path $_ })]
$ConvertWindowsImageScriptPath = 'D:\work\NanoServerSetup\Convert-WindowsImage.ps1'
@mhenrixon
mhenrixon / JobRegistry.cs
Created January 10, 2011 11:03
A quick way to setup quartz with structuremap
internal class JobRegistry :Registry
{
public JobRegistry()
{
ForSingletonOf<PlaynGO.Common.InversionOfControl.IContainer>().Use<PlaynGO.StructureMap.Container>();
ForSingletonOf<IJobFactory>().Use<WpsJobFactory>();
var col = new NameValueCollection();
ForSingletonOf<ISchedulerFactory>().Use<StdSchedulerFactory>().Ctor<NameValueCollection>("props").Is(ctx =>
{
@haf
haf / gist:5629584
Last active January 23, 2019 20:59
Finding the private key of a Windows certificate from PowerShell/C#.
namespace PKI
{
class Results : IEquatable<Results>
{
internal static readonly Results NotFound = new Results
{
Directory = "",
KeyName = ""
};
@tcaddy
tcaddy / check_student_planning.js
Last active March 16, 2018 08:14
A PhantomJS script to monitor Ellucian Student Planning / Self-Service for unresponsiveness. A PowerShell script to run the PhantomJS script and recycle the app pool, send an email.
/*
Student Planning goes down randomly and we have to recycle the app pool to fix it.
This script will try to login to Student Planning and make an AJAX request. It will
return text output (console.log() output) about whether it is working or not.
NOTE: this script relies on PhatomJS, which you can download here:
http://phantomjs.org/download.html
NOTE: change the values of the host, user, and pass variables. Optionally change the timeout variable.
*/
@andrerocker
andrerocker / sqlserver-dump.ps1
Created October 30, 2010 22:12
Powershell Script to: Export all data from yours SQLServer like mysqldump
$database_host = "<host>"
$database_name = "<database>"
$output_file = "<output_file>"
$user = "<username>"
$password = "<password>"
[system.reflection.assembly]::loadWithPartialName('Microsoft.SqlServer.SMO')
$server = new-object "Microsoft.SqlServer.Management.Smo.Server" $database_host
$server.connectionContext.loginSecure = $false