Skip to content

Instantly share code, notes, and snippets.

@falvarez
falvarez / docker-shell.sh
Created January 24, 2018 08:10
Run docker container, mount current working directory and get interactive shell
docker run -ti -v $(pwd):/tmp DOCKER_IMAGE /bin/bash
@itsthedoc
itsthedoc / Test-IWRBasicAuth.ps1
Created November 22, 2017 15:59
Powershell example script to create headers to submit an HTTP request with basic auth
$user = "USERNAME"
$pass = "PASSWORD"
$pair = "${user}:${pass}"
#Encode the string to the RFC2045-MIME variant of Base64, except not limited to 76 char/line.
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
#Create the Auth value as the method, a space, and then the encoded pair Method Base64String
$basicAuthValue = "Basic $base64"
## Load assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.SqlParser") | Out-Null
$ParseOptions = New-Object Microsoft.SqlServer.Management.SqlParser.Parser.ParseOptions
$ParseOptions.BatchSeparator = 'GO'
## No Errors
$Sql = "Select * from sys.sysdatabases"
$Script = [Microsoft.SqlServer.Management.SqlParser.Parser.Parser]::Parse($SQL, $ParseOptions)
$Script.Errors
// serviceUri - the fabric address of the service you want to query for partitions
// this gist assumes your service has an Int64 partitioning scheme.
var fabricClient = new FabricClient();
var servicePartitionList = await fabricClient.QueryManager.GetPartitionListAsync(serviceUri);
IList<Int64RangePartitionInformation> partitionKeys = new List<Int64RangePartitionInformation>(servicePartitionList.Count);
foreach (var partition in servicePartitionList)
{
var int64PartitionInfo = partition.PartitionInformation as Int64RangePartitionInformation;
@computerality
computerality / gist:48666348cbf8980a3204f1e3ae84c55e
Created November 30, 2016 22:57
How to Install .NET Framework 2.0 on Windows Server 2016 offline
Prerequisites:
You have a piece of old software you need to run but it requires .net 2.0 to install.
Steps to install .net framework 2.0:
1. Download .net framework from microsoft.com.
2. Realize it is x64 and not x86 as needed.
3. Download .net framework 2.0 sp2 from microsoft.com
4. Realize it is only the service pack and does not include the installer.
5. Find a USB cd rom drive.
6. Copy the exe off of the cd.
@pregress
pregress / gist:5820672
Created June 20, 2013 06:30
TraverseTree
public static IEnumerable<T> TraverseTree<T>(this T parent, Func<T, IEnumerable<T>> getChildren)
{
yield return parent;
foreach (var child in getChildren(parent))
{
foreach (var item in child.TraverseTree(getChildren))
{
yield return item;
}
}
@tdewilde
tdewilde / Int32.ToGuid()
Last active December 17, 2015 20:48
Extension method to convert an integer to a Guid. Useful for mocking objects in a unit test.
public static Guid ToGuid(this int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
@timheuer
timheuer / gistdiff.ps1
Created August 22, 2012 05:45
My hack start at creating a script for auto-submitting a diff to gist.github.com
# ask the user for a gist name
param (
[string]$gistname = "$(Read-Host 'Enter a name for the gist')"
)
# constant
$gistapi = "https://api.github.com/gists"
$filename = $gistname + '.diff'
$teststring = "`{`"description`": `"the description for this gist`",`"public`": true,`"files`": `{`"file1.txt`": `{`"content`": `"String file contents`"`}`}`}"
# get the diff from the current session
@jstangroome
jstangroome / Deploy-SSRSProject.ps1
Created July 3, 2012 22:37
PowerShell scripts to deploy a SQL Server Reporting Services project (*.rptproj) to a Reporting Server
#requires -version 2.0
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidatePattern('\.rptproj$')]
[ValidateScript({ Test-Path -PathType Leaf -Path $_ })]
[string]
$Path,
[parameter(
@markembling
markembling / hosts.ps1
Created August 24, 2009 13:38
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {