Skip to content

Instantly share code, notes, and snippets.

View ndrscodes's full-sized avatar
💡
gathering knowledge

Andreas Schmidt ndrscodes

💡
gathering knowledge
View GitHub Profile
@ndrscodes
ndrscodes / Primes.java
Created May 3, 2023 09:39
A simple java program showing a problem using stream reduction in order to count prime numbers in a list.
package primes;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
@ndrscodes
ndrscodes / ContentController.java
Created May 2, 2023 02:32
the simplest Spring Boot JMS Request-Reply sample
package com.example.demo_jms;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.web.bind.annotation.PostMapping;
@ndrscodes
ndrscodes / settime.sh
Last active September 14, 2022 18:54
a simple bash script for setting a client's time via NTP if the current system time is so far off that a local DNS server is unable to resolve hostnames.
#!/bin/bash
NTP_SERVICE="/etc/init.d/ntp"
URL="timeapi.io"
ENDPOINT="/api/TimeZone/zone?timeZone=Europe/Berlin"
DNS="8.8.8.8"
IP=$(nslookup $URL $DNS | egrep -o "([0-9]{1,3}\.){1,3}[0-9]{1,3}" | tail -n 1)
echo "server ip seems to be $IP"
@ndrscodes
ndrscodes / obfuscate.sh
Last active January 18, 2022 22:55
Creates an obfuscated version of any string you pass to it. The result is wrapped inside a randomly named function that you can call in order to retrieve the original string. You can pass the --readable (-r) flag as the first argument in order to get a more readable version of the function. If multible words are passed (which are not passed as a…
#!/bin/bash
# Copyright 2022 ndrscodes (Andreas Schmidt)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@ndrscodes
ndrscodes / parser.cs
Created October 19, 2021 17:42
O(n) way of parsing golang-formatted duration strings to TimeSpans in C#
/// <summary>
/// Highly performant method for parsing strings using the GoLang TimeSpan format (e.g. 23h59m59s)
/// If no time unit is specified, seconds will be assumed.
/// </summary>
/// <param name="str">the string to parse</param>
/// <returns>a TimeSpan representing the parsed value</returns>
public static TimeSpan ParseTimeSpan(string str)
{
if (str == null || string.IsNullOrWhiteSpace(str))
throw new ParseException("input may not be empty");