Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / OctokitDotNet.ps1
Last active August 29, 2015 13:55
Sample code to get issue from GitHub repository using Octokit.net
Use-NuGetPackage Octokit -Verbose
#Get Issues from GitHub repositories
$client = New-Object Octokit.GitHubClient("PowerShellClient")
$task = $client.Issue.GetForRepository("altrive", "PSCodeAnalyzer")
#Show results
$task.Result | Out-GridView
#Usage: Show-BallonTip "Title" "Message"
function Show-BalloonTip
{
[CmdletBinding()]
param (
[Parameter(Mandatory, Position = 0)]
[string] $Title,
[Parameter(Mandatory, Position = 1)]
[Linq.Enumerable]::Any((Get-Service), [Func[object, bool]]{ param ($p) $p.Status -eq "Running" })
[Linq.Enumerable]::Where((Get-Service), [Func[object, bool]]{ param ($p) $p.Status -eq "Running" })
@altrive
altrive / Invoke-WithProgress.ps1
Last active August 29, 2015 13:56
Write-Progress wrapper sample code
function Main
{
$ErrorActionPreference = "Stop"
Invoke-WithProgress -Activity "Test" -Action {
foreach ($i in 1..100)
{
$progress.UpdateProgress($i)
sleep -Milliseconds 10
}
@altrive
altrive / Mono.CSharp.ps1
Last active August 29, 2015 13:56
Call C# code snipped from PowerShell using Mono.CSharp/Roslyn
Use-NuGetPackage Mono.CSharp -Verbose
#Setup Mono C# evaluater
$settings = New-Object Mono.CSharp.CompilerSettings
$printer = New-Object Mono.CSharp.ConsoleReportPrinter
$context = New-Object Mono.CSharp.CompilerContext($settings, $printer);
$evaluator = New-Object Mono.CSharp.Evaluator($context);
$evaluator.Run("using System; using System.Linq") > $null
#Define Func<int,int> return n^2
function Main
{
#1.No attribute
$a = 5;
Write-Host ($a) #5
#2.With Add Value attribute
[AddValue(5)]
$b = 5;
Write-Host $b #5+5 =10
function Main
{
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Net.Http
Write-Host ("Before: {0} MB" -f ([GC]::GetTotalMemory($true) / 1MB))
foreach ($i in 1..1000)
{
Get-ContentFromUrl -url "http://localhost" > $null
}
param (
$RequestUrl = "http://127.0.0.1"
)
function Main
{
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Net.Http
#Reuse connection
Use-NuGetPackage ManagedEsent -Verbose #Require PSNuGet<https://github.com/altrive/PSNuGet>
$dictionary = New-Object 'Microsoft.Isam.Esent.Collections.Generic.PersistentDictionary[string,string]'("TempData")
try
{
$key = Read-Host -Prompt "Enter key"
if ($dictionary.ContainsKey($key))
{
Write-Host "Key($key) is already exists"
}
$stream = $null
try
{
$stream = [IO.File]::Open($packagePath, [IO.FileMode]::Create)
#$builder.Save($stream);
}
finally
{
if ($stream -ne $null)
{