Skip to content

Instantly share code, notes, and snippets.

@naraga
naraga / PCQueueDemo.cs
Created September 18, 2012 22:08
Producer / Consumer queue optimized for IO bound operations
class Program
{
// PcQueue - demo
// Code copied from "C# 5.0 in a Nutshell: The Definitive Reference" by Joseph Albahari and Ben Albahari
// Modified by @borisbucha to efficiently support IO bound operations (simply adding TaskCreationOptions.LongRunning to consumer tasks)
// which sugests to scheduler to allocate dedicated thread to enqued items instead of poluting Threadpool.
static void Main()
{
Console.WriteLine("press any key when ready");
Console.ReadLine();
@naraga
naraga / write_build_out.ps1
Created August 26, 2012 09:23
Writes build output to the host highlighting error messages in red.
cat build_out.txt | %{switch -regex ($_) {"^err:" {write-host $_ -backgroundcolor "red"} default {write-host $_}}}
@naraga
naraga / profile.ps1
Created August 2, 2012 21:32
Poor man's Git prompt
function Get-GitRepoPath
{
@( $i=0;`
$pwd.path -split "\\"| `
%{"$(@($pwd.path -split '\\')[0..$i] -join '\')";$i++} | `
? {test-path "$_\\.git"})[0]
}
function Get-GitCurrentBranch
{
@naraga
naraga / run_mssql_query.ps1
Created July 27, 2012 22:07
Executes MSSQL query and pushes output (as PSCustomObject objects) into pipe
function SelectFrom-Mssql([string] $selectQuery)
{
. sqlcmd -S "(local)" -d `"mydb`" `-Q "SET NOCOUNT ON $selectQuery" -s "|" -W |
ConvertFrom-CSV -Delimiter "|" |
select -skip 1
}
SelectFrom-Mssql "exec sp_who"
@naraga
naraga / Pipes Yeilds
Created July 26, 2012 21:44
Yeilding objects and arrays to pipe.
function GetFewObjs()
{
New-Object PSObject -p @{
Name = "Bill"
Surname = "Gates"
}
New-Object PSObject -p @{
Name = "Barack"