Skip to content

Instantly share code, notes, and snippets.

@vors
vors / GenericMethods.ps1
Created November 6, 2015 20:20
Workaround to call to a generic method OfType<T>() in PowerShell, when PowerShell cannot figure out <T> from the context
# PowerShell can infer generic <T> for method calls for your, when it has a parameter of the same type <T>
# Example: Enumerable.Distinct<TSource>(IEnumerable<TSource>)
# TSource can be inferred from the argument
[System.Linq.Enumerable]::Distinct([int[]]@(1,2,3,1,2))
# Let's say you want to call a generic method without ability to infer types.
# Example: Enumerable.OfType<TResult>()
# Idially you may expect syntax like this
# [System.Linq.Enumerable].OfType[int](@(,@(1,2,'a'))
# where you tell PowerShell type explicitly.
@vors
vors / 42.py
Created May 13, 2022 01:14
Print 42
i = 0
while True:
i += 1
if int((i * 1024) / 1000) != i:
print(i)
break
@vors
vors / CPUKiller.txt
Last active January 19, 2022 08:49
CPUKiller PowerShell transcript
>> Register-PSSessionConfiguration -SessionType Workflow -Name CPUKiller -SessionTypeOption (New-PSWorkflowExecutionOption -MaxActivityProcesses 100)
114 [C:\windows\system32]
>> $s = New-PSSession -ConfigurationName CPUKiller
115 [C:\windows\system32]
>> icm $s {
>>> workflow Test-Myworkflow {
>>> param
>>> (
@vors
vors / xmlToString.ps1
Created March 21, 2015 21:13
PowerShell function to convert any [xml] element to string
function Convert-XmlElementToString
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$xml
)
$sw = [System.IO.StringWriter]::new()
$xmlSettings = [System.Xml.XmlWriterSettings]::new()

Old master of Jeet Kune Do taught me a lesson once. I was doing all sorts of small errands for him at the time. I struggled with moving a particularly big stone in the garden.

He invited me to join for a cup of tea and gave me a lesson in Jeet Kune Do and gardening. First he invited me to watch how the grass is growing with him. And I paid attention. Second he invited me to look at the cup that I drank tea from. And I paid attention.

And lastly he said: "If you watch how grass grows for long enough, if you look at the cup long enough, somebody will do your work for you".

@vors
vors / sv_machine.hash
Created May 5, 2021 22:12
hash of sv_machine reference implementation
e199d0da7908f1895cac5c645806ec1a0f03a409
@vors
vors / hello.ipynb
Created April 17, 2021 03:58
hello.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vors
vors / SlackAutoInvite.js
Last active May 9, 2020 17:51
Automation for sending Invites on Slack. Based on Google Forms and Google script. For more context read https://levels.io/slack-typeform-auto-invite-sign-ups/
/*
To automate your slack instance invites,
1. Create a google form with two text fields:
"Your email"
"Who invite you"
2. You will get a google table with responses and 3 fields:
1) "Timestamp"
@vors
vors / arc_sample.rs
Created June 25, 2018 02:05
Rust toy example for Arc where tsan reports a data race
use std::sync::Arc;
use std::thread;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped!");
}
}
@vors
vors / platyPS-applicable.md
Created June 5, 2017 06:17
Demo for new New-ExternalHelp -ApplicableTag functionality in platyPS 0.8.0

Context

See PowerShell/platyPS#273

Before

Before if we have similar modules, or different version of the same module, we would need to have separate markdown files.

For example, let's say we have 4 modules: