Skip to content

Instantly share code, notes, and snippets.

View Molochnikov's full-sized avatar
🏠
Working from home

Molochnikov

🏠
Working from home
View GitHub Profile
function b() {
function a() {
function d() {
$f = (new-item -path ("function:test") -value {Write-Host Hello!});
$context = $host.runspace.gettype().getmethod("get_ExecutionContext",([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)).Invoke($host.runspace,$null)
$ss = $context.gettype().getmethod("get_EngineSessionState",([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)).Invoke($context,$null)
$scope = $ss.gettype().getmethods(([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)) | Where-Object {$_.name -eq "GetScopeByID"} | ForEach-Object {try {$_.Invoke($ss,1)} catch {}}
$funct = $scope.gettype().getmethod("get_FunctionTable",([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)).Invoke($scope,$null)
$Funct.Add('SayHello', $f)
}
@Molochnikov
Molochnikov / SOLID_DI_V.md
Last active June 11, 2023 11:21
No bullshit guide to SOLID and DI in V

No bullshit guide to SOLID and DI in V

Refactoring

Refactoring is the process of restructuring existing computer code without changing its external behavior. Refactoring wastes programmer's time (and someone's money) in efforts to improve code readability and reduced complexity. Careless refactoring can create new bugs and errors, accidentally changes in code behavior. Diffs in version control system are chaotic and big in every "Refactoring" commit that you can't even explain with one commit message. You can't even merge without conflicts if you are refactoring some code which actively developed by others. If refactoring is so hard why programmers do it?

Changes is the answer. Code always develops with new business requirements. Some things and rules that yesterday was rock-solid today seems wrong. Because something already written we need to save existing right behaviour with having ability to add new functionality.

Can we write our code to be ready for any new requirement and any new chang

@Molochnikov
Molochnikov / PowerShellEventExample.ps1
Created May 23, 2023 12:02
Using .NET events in PowerShell classes
class PowerShellEventExample {
#if method for initial delegate exists in class:
#hidden [void]test([object]$o, [EventArgs]$a) {
# Write-Host 'test'
#}
#hidden [EventHandler]$handler = [Delegate]::CreateDelegate([EventHandler], $this, 'test', $false)
hidden [EventHandler]$handler = [EventHandler]{param([object]$o, [EventArgs]$a)}
hidden [Threading.SemaphoreSlim]$SomeEventInterlockedSemaphore = [Threading.SemaphoreSlim]::new(1, 1)
[void]add_SomeEvent([EventHandler]$value) {
@Molochnikov
Molochnikov / js.ps1
Last active February 14, 2022 12:39
ps.js
function arguments() {
$dict = iex('gv PSBoundParameters -scope 1 -ValueOnly');
$dict = iex('@($dict[$dict.keys])');
$pars = iex('(gv myinvocation -Scope 1 -ValueOnly).MyCommand.parameters');
$en = $pars.GetEnumerator();
$arr = iex('New-Object System.Object[] 0');
$j = 0;
while ($en.MoveNext()) {
iex('sv -name $en.Current.Value.Name -value $dict[$j] -scope 1');
$arr += $dict[$j];
@Molochnikov
Molochnikov / Add-CmdletFromCS.ps1
Last active June 2, 2026 15:24
Add cmdlet to current runspace session state without snapins and modules
$test = @'
namespace Microsoft.Samples.PowerShell.Runspaces
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using PowerShell = System.Management.Automation.PowerShell;
#region GetProcCommand
@Molochnikov
Molochnikov / PSTelegramBotClient.ps1
Last active January 20, 2022 21:44
Can send messages and files
[System.Net.ServicePointManager]::SecurityProtocol = `
[System.Net.SecurityProtocolType]::Tls12
function Invoke-MultipartFormDataUpload
{
[CmdletBinding()]
PARAM
(
[string][parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]$InFile,
[string]$ContentType,
Measure-Command {-1..-25000 | % {$i=-1} {$i++;@{i=$i;o=$_}} | group {[int]($_.i/4999)} | Out-Default}
function Download-AppxPackage {
[CmdletBinding()]
param (
[string]$Uri,
[string]$Path = "."
)
process {
$Path = (Resolve-Path $Path).Path
#Get Urls to download
@Molochnikov
Molochnikov / Find in folder.ps1
Last active November 24, 2021 12:25
Find in folder
gci | where { $_.LastWriteTime -ge "10/18/2021" } | sls -Pattern 'HMCIS1578680'
@Molochnikov
Molochnikov / model.py
Last active November 11, 2021 22:31
Neural network model, server, test
optimizer = 'rmsprop'
dim = 32
epochs = 1000
batchsize = 4096
filepath= "weights.best.hdf5"
filename = "shuf_new_sales_uniq.csv"
model_name = filepath#"model.h5"
multilayer = True
nlayers = 9