Skip to content

Instantly share code, notes, and snippets.

@bpatra
bpatra / AssemblyInfo.cs
Last active August 29, 2015 14:03
A sample assembly info file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("armenAnalytics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("armenAnalytics")]
[assembly: AssemblyCopyright("Copyright © 2014")]
@bpatra
bpatra / PatchAssemblyInfo.ps1
Last active August 29, 2015 14:03
the detail of the PatchAssemblyInfo task
Task PatchAssemblyInfo{
function GetAssemblyVersion {
#skip the details for now -> returns the version major.minor (e.g. "6.7")
}
function GetAssemblyFileVersion {
#skip the details for now -> returns the long version major.minor.build (e.g. "6.7.35698")
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
@bpatra
bpatra / bootstrap.ps1
Last active August 29, 2015 14:03
This script loads all file and defines the high level targets
#load all targets
Get-ChildItem (Join-Path $PSScriptRoot -ChildPath "./targets") | ForEach-Object{ & $_.FullName }
Task Example -Depends PatchAssemblyInfo, RenameMSI {
Write-Host "Example target executed"
}
@bpatra
bpatra / functionPatchAssemblyInfo.ps1
Created July 8, 2014 21:02
Details of the functions used in the PatchAssemblyInfo PSake task
function GetRevisionNumber {
$major = "1"
$minor = "0"
#we use the environment variable BUILD_NUMBER provided by teamcity, use -1 is not found to test locally the process
$patch= if ([string]::IsNullOrEmpty($env:BUILD_NUMBER)) { "-1" } else { $env:BUILD_NUMBER }
$major + "." + $minor + "." + $patch
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
@bpatra
bpatra / gist:bd641ee939f2c70ed3d9
Last active August 29, 2015 14:04
Choosing the proper registry
RegistryKey baseRegistryHklm;
RegistryKey baseRegistryHkcu;
if (Environment.Is64BitOperatingSystem) //Use OS not process...
{
baseRegistryHklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
baseRegistryHkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
}
else
{
baseRegistryHklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
@bpatra
bpatra / YAML extractor
Created August 24, 2014 13:18
Powershell script for extracting YAMLS out of Jekyll files
#Script for extractingn YAML of .html files.
#The extracted content is put in a directory YAMLS <websiteroot>/ignored/YAMLS
if(-Not (Test-Path (Join-Path $PSScriptRoot -ChildPath "ignored"))){
throw "It is assumed that a directory ignored exists"
}
function ContainsYAML([string] $htmlFile){
$lines = Get-Content $htmlFile
$lineCount = $lines.Length - 1
$indices = (0 .. $lineCount)
@bpatra
bpatra / Nice gitlog
Created December 4, 2014 09:59
A nice Powershell gitlog to view your commits
function GitLog
{
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
}
@bpatra
bpatra / gist:6074217
Last active December 20, 2015 04:49
Implementation of a "tree builder" using mutability of the data structure
type Tree =
|Node of string*list<Tree ref>
|Empty
//create tree from a branch
let rec branchToTree (inputList:list<string>) =
match inputList with
| [] -> Tree.Empty
| head::tail -> Tree.Node (head, [ref (branchToTree tail)])
@bpatra
bpatra / gist:6074329
Last active December 20, 2015 04:58
Using the mutable tree and its mergeInto function introduced ingist:6074217
let tree = ref Tree.Empty
let branch1 = ["a";"b";"c"]
let branch2 = ["a";"b";"d"]
let branch3 = ["a";"f"]
do mergeInto tree branch1
do mergeInto tree branch2
do mergeInto tree branch3
//the following tree is created
// a
@bpatra
bpatra / gist:6074448
Last active December 20, 2015 04:59
Labeled tree and the zipper pattern
type Tree =
| TreeNode of string* Tree list
| Empty
member this.GetLabel =
match this with
| Empty -> failwith "cannot get the label of an empty tree"
| TreeNode(lbl,_) -> lbl
//transform the branch into a tree
let rec branchToTree (inputList:list<string>) =