Skip to content

Instantly share code, notes, and snippets.

@SMoni
SMoni / createEnumaration.js
Last active December 31, 2022 10:04
Simple function to create an enumeration (sort of), in which the key and the value match.
'use strict';
const createEnumeration = (...keys) =>
keys.reduce(
(result, key) => Object.assign(result, { [key]: key }),
{}
);
const myEnum = createEnumeration(
'first',
@SMoni
SMoni / do_magic.py
Created December 26, 2022 13:49
What will this method do...
def do_magic(decimal_num:int):
if decimal_num < 2:
return decimal_num
result = 0
square_num = 2
while square_num < decimal_num:
square_num *= 2
@SMoni
SMoni / Quips
Last active September 19, 2022 17:59
Ganz schlaues...
Jedes Problem wird solange mit MSExcel bearbeitet, bis bemerkt wird, dass es nicht verstanden wurde.
When there’s no more room in your Repo. Then dead code will be in the deployment
and coders won’t have a commit. Cause it’s the dawn of the dead code
Wenn die Schnittstelle schwer zu verstehen ist und eine Dokumentation braucht,
dann ist die Schnittstelle unter Umständen nicht wirklich gut.
Eine schlechte Schnittstelle wird durch eine Dokumentation nicht besser.
Es geht nicht darum, es richtig zu machen, sondern nicht falsch!
@SMoni
SMoni / Copy-Dependencies.ps1
Last active June 30, 2022 18:49
Copy all npm-packages for production into the dist-folder
Clear-Host
Set-Location $PSScriptRoot
$main = {
npm list --prod |
Select-Object -Skip 1 | # First line is the project itself
Get-Dependency |
Sort-Object |
Get-Unique |
const myArray = Array.from({length: 10}, (e, i)=> i)
doWork(
doSomethingWith,
myArray,
logToConsole
)
//Die Funktion, die das Ganze abarbeitet
async function doWork(doSomething, anArray, aCallback) {
$sample = @(
[PSCustomObject]@{
From = [datetime]::Parse("01.01.2022 00:00:00")
To = [datetime]::Parse("10.01.2022 23:59:59")
}
[PSCustomObject]@{
From = [datetime]::Parse("05.01.2022 00:00:00")
To = [datetime]::Parse("15.01.2022 23:59:59")
}
[PSCustomObject]@{
@SMoni
SMoni / ConvertFromCsv.cs
Last active December 5, 2021 12:22
Converts Csv with header from a TextReader
public static class ReadFromCsv {
public static IEnumerable<IDictionary> asKeyValuePairs(this TextReader Reader_, string Delimiter_ = ";") {
var splitThis = Delimiter_.asSplitter();
var result = new List<Dictionary<string, object>>();
var columns = splitThis(Reader_.ReadLine());
@SMoni
SMoni / combineGuids.ps1
Created July 5, 2021 10:41
Combine two guids
function combineIds() {
param(
[Parameter()]
[Guid]$First,
[Parameter()]
[Guid]$Second
)
function getStartOfWeek() {
begin {
$base = [DayOfWeek]::Monday
}
process {
$difference = $_.DayOfWeek - $base
$offset = (7 + $difference) % 7 * -1