Skip to content

Instantly share code, notes, and snippets.

View petrsvihlik's full-sized avatar
😋
Strategizing...

Petr Švihlík petrsvihlik

😋
Strategizing...
View GitHub Profile
@petrsvihlik
petrsvihlik / nested_discard.cs
Created September 30, 2022 08:43
Nested discard parameters
Func<string, string, string> action = new Func<string, string, string>((_, parameter) =>
{
string function(string x)
{
Console.WriteLine(x);
return x;
}
_ = function(parameter);
return "whatever";
});
@petrsvihlik
petrsvihlik / gist:9076c8eb333c0b4617377be50f4fae81
Created August 17, 2022 12:45
Some swift enum hocus pocus
import Foundation
public enum ShapeRawEnum: String, RawRepresentable {
case square
case circle
public var requestString: String {
return self.rawValue
}
@petrsvihlik
petrsvihlik / arguments.py
Created July 22, 2022 08:57
Demonstration of all kinds of required and optional arguments in Python.
# positional, keyword or positional args - https://www.educative.io/answers/what-are-positional-only-arguments-in-python
# keyword-only args - https://peps.python.org/pep-3102/
# kwargs - https://www.w3schools.com/python/gloss_python_function_arbitrary_keyword_arguments.asp
from typing import Optional
"""two
Function that demonstrates all kinds of required and optional arguments.
:keyword kwarg_optional: optional kwarg
"""
@petrsvihlik
petrsvihlik / fetchSigningKey.js
Created July 18, 2022 09:37
Azure AD & JWKS & PEM & Express.js validation
const getPem = require('rsa-pem-from-mod-exp');
const fetch = require('node-fetch');
const jwt = require('jsonwebtoken');
var keysUri = `https://login.microsoftonline.com/${process.env.AAD_TENANT_ID}/discovery/keys?appid=${process.env.AAD_CLIENT_ID}`;
fetch(keysUri, { redirect: 'manual' }).then(response => response.json())
.then(data => {
var decodedToken = jwt.decode(token, { complete: true });
var key = data.keys.find((_key) => _key.kid === decodedToken.header.kid);
@petrsvihlik
petrsvihlik / gist:a4b762ddd284812690dcef6a8d18ab67
Last active October 15, 2021 22:48
Android Games Worth Your Toilet Time
Admit it!
# TOP 10
#1 Ninja Arashi series (1 & 2)
#2 Rusty Lake's Cube Escape series
#3 Eufloria HD
#4 Alto's series (Adventure & Odyssey)
#5 Ultraflow series (1 & 2)
#6 Lyne
#7 Prune
(new-object System.Net.WebClient).DownloadFile('http://dl.google.com/chrome/install/375.126/chrome_installer.exe', 'c:/temp/chrome.exe');. c:/temp/chrome.exe /silent /install;rm c:/temp -rec
# or
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path$Installer; Start-Process -FilePath $Path$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path$Installer
@petrsvihlik
petrsvihlik / git.sh
Last active March 14, 2022 08:01
Rocky's Personal Cheat-sheet
# Revert commit
git reset --hard <old-commit-id>
git push -f <remote-name> <branch-name>
# Refresh remote branches list
git remote update origin --prune
# Edit last commit message
git commit --amend
@petrsvihlik
petrsvihlik / appveyor.yml
Last active December 1, 2019 20:42
Running .NET Core 3 XUnit code coverage in AppVeyor using OpenCover and Codecov
# Add this to your YML file
install:
- cinst opencover.portable
- cinst codecov
test: off
test_script:
- ps: ./coverage.ps1
@petrsvihlik
petrsvihlik / GitHub-GraphQL-PowerBI.m
Last active February 16, 2024 17:16
Loading GraphQL data (GitHub API v4) into PowerBI
// This script shows how to use M language (Power Query Formula Language)
// to read data from GitHub API v4 using a POST request.
// This can come in handy when building PowerBI reports that utilize GraphQL endpoints for loading data.
let
vUrl = "https://api.github.com/graphql",
vHeaders =[
#"Method"="POST",
#"Content-Type"="application/json",
#"Authorization"="Bearer <your_personal_token_here>"
# Configure path to the root of your web project
$webRoot = "C:\inetpub\wwwroot\Kentico\CMS\"
$bin = $webRoot + "bin\"
# Load settings from web.config
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $webRoot + "web.config")
Add-Type -AssemblyName System.Configuration
[Configuration.ConfigurationManager].GetField("s_initState", "NonPublic, Static").SetValue($null, 0)
[Configuration.ConfigurationManager].GetField("s_configSystem", "NonPublic, Static").SetValue($null, $null)
([Configuration.ConfigurationManager].Assembly.GetTypes() | where {$_.FullName -eq "System.Configuration.ClientConfigPaths"})[0].GetField("s_current", "NonPublic, Static").SetValue($null, $null)