Skip to content

Instantly share code, notes, and snippets.

@shinayser
shinayser / kill_steam.ps1
Last active December 21, 2021 15:32
Kill steam process
$steam = Get-Process steam -ErrorAction Ignore
if ($null -eq $steam) {
Write-Output "Steam not found"
}
else {
$steam.Kill($true)
Write-Output 'Steam is dead'
}
# Looking for a object in path
Get-Command flutter
# Extracting a property from it
Get-Command flutter | Select-Object -ExpandProperty source
# Advanced String Interpolation (with expressions)
Get-ChildItem | ForEach-Object { Write-Output "The lenght: $($_.Length)" }
@shinayser
shinayser / Powershell toPascal-toSnakeCase.ps1
Last active February 7, 2023 01:33
Functions to convert text into Pascal or Snake case
function toPascalCase([string] $text) {
return $text -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
}
function toSnakeCase([string] $text) {
$text = $text -replace '\s+', '_' # Replace spaces with underscores
$text = $text -replace '[-\.]', '_' # Replace dashes and dots with underscores
$text = $text -creplace '(?<![-_A-Z])(?<!^)[A-Z]', { "_$_" } # Insert underscores before uppercase letters
return $text.ToLower()
}
@shinayser
shinayser / Normalizing GIT file endings.txt
Last active February 13, 2023 21:35
Normalizing git file endings to LF
git config --global core.autocrlf false
@shinayser
shinayser / Get-FlutterHotFixes.ps1
Last active April 1, 2023 21:17
Fetches all flutter hotfixes on stable branch
function Get-FlutterHotFixes([int]$Amount = 2) {
$url = "https://raw.githubusercontent.com/wiki/flutter/flutter/Hotfixes-to-the-Stable-Channel.md"
$regex = "###\s*\[?(?<Version>\d+.\d+.\d+)\]?(?<Url>.*)\s(?<Changes>[\s\S]+?)(?=#+)"
Invoke-RestMethod $url | Select-String -Pattern $regex -AllMatches | ForEach-Object {
$_.Matches | ForEach-Object { [pscustomobject]@{
Version = $_.Groups[1].Value
Url = $_.Groups[2].Value
Changes = $_.Groups[3].Value
}
}
@shinayser
shinayser / Start-Emulator.ps1
Created May 4, 2023 14:25
Starts an Android Emulator (with completions)
function Start-Emulator(
[ArgumentCompleter({
param(
$CommandName,
$ParameterName,
$WordToComplete,
$CommandAst,
$FakeBoundParameters
)
@shinayser
shinayser / value_listenable_stream.dart
Created August 9, 2019 20:34
A function that converts a ValueListenable to a Stream
Stream<T> valueListenableToStreamAdapter<T>(ValueListenable<T> listenable) {
StreamController<T> controller;
void listener() {
controller.add(listenable.value);
}
void start() {
listenable.addListener(listener);
}