Skip to content

Instantly share code, notes, and snippets.

View pizycki's full-sized avatar

Paweł Iżycki pizycki

View GitHub Profile
Examiner updates his notification settings to receive reminder for every work 2 days early at 15:00 local time
RescheduleUcomingExaminerWorkNotifications(examinerId) =
Get examiner notification preferences
Get examiner upcoming work assignments
notifications = Calculate notifications for schedule
for each
date, time = take work assignment time
date = Find {n}-th day before assignment date
next notification date = date + time
@pizycki
pizycki / marten.fsx
Last active February 3, 2020 16:53
Open conn, store and simple query
https://martendb.io
open Marten
[<CLIMutable>]
type User =
{ Id : Guid
Name : string }
let store =
@pizycki
pizycki / Delete-old-branches.fs
Created January 24, 2020 10:52
Delete old Git branches, filtered by name and date
let inline (--) (x:string) (y:string) = x.Replace(y, String.Empty)
module Wildcards =
let private wildcardToRegular wc =
"^" + Regex.Escape(wc).Replace("\\*", ".*") + "$"
let accepts wildcard branch =
let regex = wildcardToRegular wildcard
let rgx = new Regex(regex, RegexOptions.IgnoreCase)
rgx.IsMatch(branch)
@pizycki
pizycki / GenericOptions.cs
Created November 27, 2019 13:30
Generic IOptions
public class GenericOptions<T> : IOptions<T> where T : class, new()
{
public GenericOptions(T value)
{
Value = value ?? throw new ArgumentNullException(nameof(value));
}
public T Value { get; }
}
@pizycki
pizycki / Shutdown-PC.ps1
Last active November 4, 2019 21:17
PowerShell wrapper for shutdown.exe
function Shutdown-PC {
param (
[int] $Minutes = 5
)
$seconds = 60 * $Minutes
$exp = "shutdown /s /t $seconds"
$exp | Write-Host
$exp | Invoke-Expression
if($LASTEXITCODE -eq 0){
@pizycki
pizycki / Git-Module.ps1
Created November 2, 2019 21:56
My Powershell Git Helpers
### Git ###
function Git-Status { git status }
Set-Alias gs Git-Status
function Git-Log {
$cmd = "git log -10 --oneline"
Invoke-Expression $cmd
}
@pizycki
pizycki / combine.fs
Created October 12, 2019 17:03
F# Combine List of Results
open Microsoft.FSharp.Collections
/// Combines collection of Results into List of Values or Errors.
/// List<Result<'a, 'b>> -> Result<List<'a>, List<'b>>
let combine (results: List<Result<'a, 'b>>): Result<List<'a>, List<'b>> =
let rec _combine (ok: List<'a>) (err: List<'b>) (res: List<Result<'a, 'b>>) =
res |> List.tryHead
|> function
| None -> (ok, err)
| Some curr ->
@pizycki
pizycki / Docker-Module.ps1
Last active October 22, 2019 09:52
Docker helpers
### Docker ###
function Docker-PurgeImages {
docker rmi $(docker images -q)
}
function Docker-PurgeContainers {
docker rm $(docker ps -a -q)
}
@pizycki
pizycki / New-GitIgnore.ps1
Created September 28, 2019 12:58
Creates gitignore file
function New-GitIgnore {
param(
[switch] $All = $false,
[switch] $VisualStudio = $false,
[switch] $VisualStudioCode = $false,
[switch] $Rider = $false,
[switch] $InteliJ = $false
)
$url = "https://gitignore.io/api/"
@pizycki
pizycki / Get-StaleBranches.ps1
Created September 6, 2019 16:56
Get old branches
param (
[Parameter(Mandatory = $true)] $RepositoryPath,
[Parameter(Mandatory = $true)] $Days
)
function Get-BranchesInRepository([string]$path){
Push-Location
try {
Set-Location $path
$branches = git for-each-ref --sort='-committerdate:iso8601' --format='%(committerdate:iso8601)|%(refname:short)|%(committeremail)|%(committername)' refs/remotes/