Skip to content

Instantly share code, notes, and snippets.

View K0NRAD's full-sized avatar

Hauke K0NRAD

  • 17:35 (UTC +02:00)
View GitHub Profile
@K0NRAD
K0NRAD / deep_sum.py
Created August 30, 2020 15:40
sum values of an array with subarrays
def deep_sum(elem):
result = 0
for item in elem:
if hasattr(item, '__len__'):
result += deep_sum(item)
else:
result += item
return result
assert deep_sum([1, -5, [50, 50, [100, 100, [2, 2]]], 100]) == 400
@K0NRAD
K0NRAD / memoice.py
Created August 22, 2020 11:27
a simple cache for time intensive operations
from datetime import datetime
from time import sleep
def memoice(func):
class MemoDict(dict):
def __init__(self, func):
super().__init__()
self.func = func
@K0NRAD
K0NRAD / keycloakAdminApiInsecure.java
Created July 2, 2019 13:29
RestTemplate keycloak Admin API insecure
@Bean
public RestTemplate keycloakAdminApiInsecure() {
try {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
@K0NRAD
K0NRAD / UnirestAdminApiKeycloakTest.java
Created April 8, 2019 15:40
keycloak admin api insecure call with unirest
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.junit.Test;
@K0NRAD
K0NRAD / insecureRestTemplate.java
Created April 8, 2019 15:21
spring boot - create insecure client with resttemplate
@Bean("non-ssl-validation")
public RestTemplate insecureRestTemplate() {
try {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
@K0NRAD
K0NRAD / SecurityConfiguration.java
Created September 17, 2017 21:27
Spring security configuration with raealtime access voter to lock a current user.
package com.example.demo.configuration;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.vote.AuthenticatedVoter;
import org.springframework.security.access.vote.RoleVoter;
@K0NRAD
K0NRAD / del_remote_repositories.sh
Created September 10, 2017 10:10
delete _remote.repositories from .m2 local maven repository
#!/bin/sh
find ~/.m2 -name _remote.repositories -delete
@K0NRAD
K0NRAD / del_ms_lastUpdate.sh
Last active July 27, 2022 08:55
Delete *.lastUpdated files in .m2 local maven repository
#!/bin/sh
find ~/.m2 -name *.lastUpdated -delete
@K0NRAD
K0NRAD / tacho-pin-belegung.txt
Last active August 22, 2020 10:48
Pinbelegung_Kombiinstrument_3er_BMW
weißer Stecker:
1 - Kontrolleuchte Fernlicht
2 - Instrumentenbeleuchtung (Klemme 58g)
3 - Kontrolleuchte Blinker rechts
4 - Kontrolleuchte Blinker links
5 - Warnleuchte elektr. Getriebesteuerung
6 - nicht belegt
7 - nicht belegt
8 - Warnleuchte DDE
@K0NRAD
K0NRAD / index.html
Last active April 25, 2017 16:42
Swagger-UI with CORS and Cookies
// Add the follow Code Snippet to index.html from swagger-ui v2.x.x
// ...
window.swaggerUi = new SwaggerUi({
url: url,
// --- --- --- ----
useJQuery: true,
authorizations: {
makeCredentialed: function() {
this.xhrFields = {withCredentials: true}; // The important bit, along with useJQuery