Skip to content

Instantly share code, notes, and snippets.

View pitermarx's full-sized avatar

ριтєя мαяχ pitermarx

View GitHub Profile
@pitermarx
pitermarx / DataPipeline.cs
Created November 3, 2023 15:28
Idea for an abstraction over TPL DataFlow
public class DataPipeline<T>
{
private static ExecutionDataflowBlockOptions Options => new() { BoundedCapacity = 1 };
private readonly IReceivableSourceBlock<T> sourceBlock;
public DataPipeline(IReceivableSourceBlock<T> sourceBlock) => this.sourceBlock = sourceBlock;
public Task Completion => sourceBlock.Completion;
public IAsyncEnumerable<T> ReceiveAllAsync(CancellationToken ct = default) => sourceBlock.ReceiveAllAsync(ct);
public DataPipeline<TOut> Activity<TOut>(Func<T, Task<TOut>> action) => Link(new TransformBlock<T, TOut>(action, Options));
@pitermarx
pitermarx / Channels.cs
Created November 3, 2023 09:51
An example on how to use channels
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
class Processor<T> where T : class
{
private readonly Channel<T> _channel = Channel.CreateUnbounded<T>();
private readonly Task processors;
public Processor(Func<T, Task> action, int numberOfConsumers = 4)
set clipboard=unnamed "Use System clipboard
set autoindent "New lines inherit the indentation of previous lines
set expandtab "Convert tabs to spaces.
set smarttab "Insert 'tabstop' number of spaces when the 'tab' key is pressed.
set tabstop=4 "Indent using four spaces.
set shiftwidth=4
set hlsearch "Enable search highlighting.
set incsearch "Incremental search that shows partial matches.
set smartcase "Automatically switch search to case-sensitive when search query contains an uppercase letter.
@pitermarx
pitermarx / otp.ps1
Created June 29, 2023 10:42
Powershell OTP function
function otp($SECRET="ABCDEFGHIJKLMNOP", $LENGTH=6, $WINDOW=30){
$span = (New-TimeSpan -Start (Get-Date -Year 1970 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0) -End (Get-Date).ToUniversalTime()).TotalSeconds
$unixTime = [Convert]::ToInt64([Math]::Floor($span/$WINDOW))
$timeBytes = [BitConverter]::GetBytes($unixTime)
[array]::Reverse($timeBytes)
$enc = [System.Text.Encoding]::UTF8
$hmac = New-Object -TypeName System.Security.Cryptography.HMACSHA1
$hmac.key = Convert-Base32ToBytes($SECRET.ToUpper())
$randHash = $hmac.ComputeHash($timeBytes)
@pitermarx
pitermarx / DesignTimeFactory.cs
Created May 4, 2023 13:22
Script to generate EF migration scripts. One per migration
public class DesignTimeFactory : IDesignTimeDbContextFactory<MyDbContext>
{
public MarketDataServiceDbContext CreateDbContext(string[] args)
=> new MyDbContext(new DbContextOptionsBuilder<MyDbContext>().UseSqlServer(args[0]).Options);
}
@pitermarx
pitermarx / Readme.md
Last active March 23, 2023 12:34
Enred Scraper with Playwright
$certPath = ".\seq\Certificates\443.pem"
$needNewCert = if (Test-Path $certPath) {
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certPath)
#should return true if cert is expired
$cert.NotAfter -lt (Get-Date)
} else {
$true
}
# download certificates if needed
if ($needNewCert) {
@pitermarx
pitermarx / Creed. Poem by Steve Turner (PT).md
Last active May 2, 2022 13:28
Creed. Poem by Steve Turner

Steve Turner, (Jornalista Britânico),

“Credo”, o seu poema satírico sobre a mente moderna

Nós cremos em Marx Freud e Darwin

Cremos que tudo está bem desde que não prejudique ninguém até onde sabemos, e na nossa melhor definição de prejudicar.

@pitermarx
pitermarx / David Berlinsky - The Devil’s Delusion.md
Last active May 2, 2022 13:27
The Devil’s Delusion: Atheism and its Scientific Pretensions

Has anyone provided a proof of God’s inexistence? Not even close. Has quantum cosmology explained the emergence of the universe or why it is here? Not even close. Have the sciences explained why our universe seems to be fine-tuned to allow for the existence of life? Not even close. Are physicists and biologists willing to believe in anything so long as it is not religious thought? Close enough. Has rationalism in moral thought provided us with an understanding of what is good, what is right, and what is moral? Not close enough. Has secularism in the terrible twentieth century been a force for good? Not even close to being close. Is there a narrow and oppressive orthodoxy of thought and opinion within the sciences? Close enough. Does anything in the sciences or in their philosophy justify the claim that religious belief is irrational? Not even ballpark. Is scientific atheism a frivolous exercise in intellectual contempt? Dead on. David Berlinsky from http://www.davidberlinski.org/devils-delusion/about.php

Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
cinst librewolf # Vimium, Bitwarden
cinst vlc
cinst zoom
cinst treesizefree
cinst lockhunter
cinst obs-studio, obs-virtualcam
cinst musescore
cinst sumatrapdf