Skip to content

Instantly share code, notes, and snippets.

View JeremySkinner's full-sized avatar

Jeremy Skinner JeremySkinner

View GitHub Profile
#r "nuget: Nuke.Common, 0.24.11"
using Nuke.Common;
Target Foo => _ => _
.Executes(() => { Console.WriteLine("Inside target"); });
BuildManager.Run(this);
function install {
$build_dir = Join-Path $PSScriptRoot ".build"
$json = ConvertFrom-Json (Get-Content "$path/global.json" -Raw)
$required_version = $json.sdk.version
# If there's a version mismatch with what's defined in global.json then a
# call to dotnet --version will generate an error.
try { dotnet --version 2>&1>$null } catch { $install_sdk = $true }
# Different PS versions may throw an exception vs set LASTEXITCODE
if ($global:LASTEXITCODE) {
$install_sdk = $true;
# From the FV buil script:
target install-dotnet-core {
# Version check as $IsWindows, $IsLinux etc are not defined in PS 5, only PS Core.
$win = (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows)
$json = ConvertFrom-Json (Get-Content "$path/global.json" -Raw)
$required_version = $json.sdk.version
# If there's a version mismatch with what's defined in global.json then a
# call to dotnet --version will generate an error. AppVeyor vs local seem to have different
# behaviours handling exit codes (appveyor will immediately halt execution on windows, but not linux)
@JeremySkinner
JeremySkinner / launch.php
Created August 7, 2018 13:11
Handle path translation for calling windows executables from WSL
#!/usr/bin/php
<?php
// In php first element of $argv is the path to the current script.
$a = $argv;
if(count($a) === 2) {
// Single argument. Just launch it.
shell_exec($a[1]);
}
@JeremySkinner
JeremySkinner / Elevate.ps1
Created June 26, 2018 13:15
Powershell - elevate command (sudo)
function Test-Administrator {
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
return $false;
}
function Elevate {
function Import-EnvFile {
$files = Get-ChildItem *.env
foreach($file in $files) {
write-host $file
$lines = Get-Content $file
foreach($line in $lines) {
if ($line -and !$line.StartsWith("#")) {
# Split by equals
$parts = $line.Split("=")
if ($parts.Length -eq 2) {
@JeremySkinner
JeremySkinner / CustomMessageBuilder.cs
Last active June 19, 2018 11:03
Message builder example
public static class Extensions {
public static IRuleBuilderOptions<T, TProperty> Prefix<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule, string prefix) {
return rule.Configure(cfg => {
cfg.MessageBuilder = context => {
// The MessageBuilderContext has lots of useful things on it, see https://github.com/JeremySkinner/FluentValidation/blob/master/src/FluentValidation/Internal/MessageBuilderContext.cs
return prefix + " " + context.GetDefaultMessage();
};
});
}
@JeremySkinner
JeremySkinner / gitutils.ps1
Last active June 13, 2018 08:54
Original gitutils that were the precusor of posh-git. Created by Mark Embling and Jeremy Skinner in 2009
function gitPrompt {
if(gitIsDirectory) {
write-host ' [' -nonewline -foregroundcolor Yellow
$status = gitStatus
$currentBranch = $status['branch']
if ($status["ahead"] -eq $FALSE) {
# We are not ahead of origin
Write-Host($currentBranch) -nonewline -foregroundcolor Cyan
} else {
public static class MyExtensions {
public IRuleBuilderOptions<T, TProperty> SetValidator<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, Func<T, IValidator<TProperty>> validatorThunk) {
return ruleBuilder.SetValidator(new LazyValidatorAdaptor<T, TProperty>(validatorThunk));
}
private class LazyValidatorAdaptor<T, TProperty> : NoopPropertyValidator {
Func<T, IValidator<TProperty>> _validatorThunk;
public LazyValidatorAdaptor(Func<T, IValidator<TProperty>> validatorThunk) {
_validatorThunk = validatorThunk;
@JeremySkinner
JeremySkinner / HashDotNetPassword.php
Created October 10, 2012 08:18
Replicating .NET Password Hashing in PHP
// From http://gilbert.pellegrom.me/replicating-net-password-hashing-in-php/
/*
* $password is the users password entered at login
* $hashed_password is the password from the database
* $password_salt is the salt from the database
*/
$bytes = mb_convert_encoding($password, 'UTF-16LE');
$salt = base64_decode($password_salt);
$password = base64_encode(sha1($salt . $bytes, true));