Skip to content

Instantly share code, notes, and snippets.

View camilohe's full-sized avatar

Camilo E. Hidalgo Estevez camilohe

View GitHub Profile
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@camilohe
camilohe / Test-RebootRequired.ps1
Created November 12, 2019 15:55 — forked from altrive/Test-RebootRequired.ps1
Check pending reboot on local computer
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-RebootRequired
{
$result = @{
CBSRebootPending =$false
WindowsUpdateRebootRequired = $false
FileRenamePending = $false
SCCMRebootPending = $false
}
@camilohe
camilohe / encrypt_openssl_using_public_key.md
Last active September 9, 2019 17:07
How to encrypt a file using openssl and a public key

How to encrypt a file using openssl and a public key

encrypt

1- get the public key in .pem format

use these commands to convert from rsa (used by ssh) to pem format

openssl rsa -in id_rsa -outform pem > id_rsa.pem
openssl rsa -in id_rsa -pubout -outform pem > id_rsa.pub.pem

2- generate a 256 bit (32 byte) random key

@camilohe
camilohe / encrypt_openssl.md
Last active September 9, 2019 16:45 — forked from dreikanter/encrypt_openssl.md
File encryption using OpenSSL

Symmetic encryption

For symmetic encryption, you can use the following:

To encrypt:

openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt:

@camilohe
camilohe / IniFormatter.cs
Created July 26, 2019 16:45 — forked from conwid/IniFormatter.cs
More complete IFormatter implementation reference for students preparing for MS 70-483
public class IniFormatter : IFormatter
{
public class IniTypeBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName) => Type.GetType(typeName.Split('=')[1]);
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
{
assemblyName = $"{IniFormatter.AssemblyNameKey}={serializedType.Assembly.FullName}";
typeName = $"{IniFormatter.ClassNameKey}={serializedType.AssemblyQualifiedName}";
}
// So you want to use anonymous interface implementations in C#? Does this lambda-based usage look ok?
// Ignore the fact that "list" and "projection" are undefined here, just note the lambdas that can close
// around any variables and procedures you want.
new AnonymousReadOnlyList<TOut>(
count: () => list.Count,
item: i => projection(list[i]),
iterator: list.AsEnumerable().Select(projection));
new AnonymousReadOnlyList<TOut>(
@camilohe
camilohe / Example1.cs
Created July 16, 2019 14:34 — forked from davidfowl/Example1.cs
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
<#
Script Name : Get-NetFrameworkVersion.ps1
Description : This script reports the various .NET Framework versions installed on the local or a remote computer.
Author : Martin Schvartzman
Reference : https://msdn.microsoft.com/en-us/library/hh925568
#>
function Get-DotNetFrameworkVersion
{
param(
[string]$ComputerName = $env:COMPUTERNAME
@camilohe
camilohe / Get-VSSolutionReferences.ps1
Created March 21, 2019 19:23 — forked from jstangroome/Get-VSSolutionReferences.ps1
Get-VSSolutionReferences.ps1
#requires -version 2.0
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string]
$Path
)
$ErrorActionPreference = 'Stop'
@camilohe
camilohe / DataExportClass.cs
Created January 17, 2019 23:02 — forked from luisdeol/DataExportClass.cs
Export List of Objects to a Comma-Separated Values (.CSV) file using C#, allowing the export of Entity Framework DbSet to CSV File. An example of use comes within the code.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace DataExportClass
{
class Program
{
public class Employee