Skip to content

Instantly share code, notes, and snippets.

Benoît Patra bpatra

Block or report user

Report or block bpatra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bpatra
bpatra / gist:9401745
Last active Aug 29, 2015
IFootballClub interface
View gist:9401745
public interface IFootballClub
{
string FullName { get; }
string NickName { get; }
int CreationYear { get; }
}
@bpatra
bpatra / restart_audioHDMIDrivers
Created Dec 21, 2013
PoSh script to restart drivers for HDMI sound
View restart_audioHDMIDrivers
$devcon = "C:\Program Files (x86)\Windows Kits\8.1\Tools\x64\devcon.exe"
$audioID = "@HDAUDIO\FUNC_01&VEN_8086&DEV_2807&SUBSYS_80860101&REV_1000\4&36161A1D&0&0001"
$displayID = "@PCI\VEN_8086&DEV_0A16&SUBSYS_130D1043&REV_09\3&11583659&0&10"
. $devcon enable $audioID
. $devcon enable $displayID
. $devcon restart $audioID
. $devcon restart $displayId
Read-Host
@bpatra
bpatra / BasicUnion
Last active Dec 26, 2015
The basic Union method in ExcelInterop
View BasicUnion
//builds the union range form the indices
private static Range Union(IEnumerable<int> rows)
{
Range range = null;
foreach (int row in rows)
{
var currentLine = ExcelAddIn.ActiveSheet.Range["A" + row + ":" + "C" + row];
range = range == null ? currentLine : ExcelAddIn.Application.Union(range, currentLine);
}
return range;
@bpatra
bpatra / ExportAliasWitExeInPath
Last active Dec 20, 2015
Part of a PoSh profile to import/export all executables located under PATH. Export-AliasWithEXEInPATH is a function that exports alias with all .exe located under PATH environment variable. The alias exported file is named alias.txt and is exported next to the $PROFILE .ps1 file. These aliases are imported just before loading module PowerTab.
View ExportAliasWitExeInPath
$aliasesPath = Join-Path -Path ([System.IO.Path]::GetDirectoryName($PROFILE)) -ChildPath "alias.txt"
function Export-AliasWithEXEInPATH
{
$aliasDict = @{}
$existingAlias = Get-Alias | ForEach-Object {$_.Name}
foreach($aliasName in $existingAlias)
{
$aliasDict.Add($aliasName,"")
}
@bpatra
bpatra / startfile
Created Aug 5, 2013
startfile for conemu
View startfile
/BufferHeight 1000 powershell
@bpatra
bpatra / gist:6098656
Last active Dec 20, 2015
F#ception. test execution with factorial
View gist:6098656
[<TestClass>]
type FsCeptionTests () =
[<TestMethod>]
member this.WithFactorial () =
let myTest = "module dafuq
let rec factorial n =
match n with
| 0 -> 1
| 1 -> 1
@bpatra
bpatra / gist:6098637
Created Jul 28, 2013
F#-ception. ExecutePsScript
View gist:6098637
let ExecPsScript<'T> script =
let runspaceConfiguration = RunspaceConfiguration.Create()
let runspaceAssemblies = runspaceConfiguration.Assemblies
let assembliesConfiguration =
PSUsableAssemblies
|> Array.map (fun asm -> new AssemblyConfigurationEntry(asm.FullName, asm.Location))
assembliesConfiguration |> runspaceAssemblies.Append
assembliesConfiguration
|> Array.map (fun asm -> asm.FileName)
|> Array.map (fun path -> new TypeConfigurationEntry(path))
@bpatra
bpatra / gist:6098589
Created Jul 28, 2013
Powershell script in simpleExample.ps1 generated by FsToPs
View gist:6098589
Add-Type -Path <myPath>\FSharp.Compiler.CodeDom.dll
$provider = New-Object Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider
$fsharpCode = @"
module dafuq
let x= 5
"@
$fsharpType = Add-Type -TypeDefinition $fsharpCode -CodeDomProvider $provider
[dafuq]::x
@bpatra
bpatra / gist:6098579
Last active Dec 20, 2015
F#-ception, testing Fs2Ps with a very simple example
View gist:6098579
let myTest = "module dafuq
let x= 5
"
//disk path to FSharp code dom provider
let codDomPath = @"<myPath>\FSharp.Compiler.CodeDom.dll"
let psCode = FsToPs codDomPath myTest "dafuq" "x"
//write script to file to test it.
use streamWriter = File.CreateText("simpleExample.ps1")
streamWriter.Write(psCode)
@bpatra
bpatra / gist:6098558
Last active Dec 20, 2015
F#-ception, building a powershell script with inlined F# from F#
View gist:6098558
let PSUsableAssemblies =
AppDomain.CurrentDomain.GetAssemblies()
|> Array.filter (fun asm -> match asm.IsDynamic with
| true -> false
| false -> File.Exists asm.Location)
let FsToPs (codeDOMProviderPath:string) (fsCode:string) moduleName returnedVariableName =
let sb = new StringBuilder()
sb.AppendFormat("Add-Type -Path {0}",codeDOMProviderPath) |> ignore
sb.AppendLine("") |> ignore
You can’t perform that action at this time.