Skip to content

Instantly share code, notes, and snippets.

View unclebean's full-sized avatar
🏠
Working from home

unclebean

🏠
Working from home
View GitHub Profile
@Service
public class ReactiveSolrService {
@Autowired
private SolrClient solrClient;
public Flux<SolrDocument> queryWithFallback(String preFilter, Predicate<SolrDocument> postFilter, int batchSize) {
return querySolrWithPreFilter(preFilter, batchSize)
.onErrorResume(e -> {
if (isBooleanQueryLimitException(e)) {
@unclebean
unclebean / ingress
Last active March 5, 2025 14:45
k8s
az network nsg rule create --resource-group <your-resource-group> --nsg-name <your-nsg-name> --name AllowHTTPHTTPS --priority 100 --direction Inbound --access Allow --protocol Tcp --source-address-prefix '*' --source-port-range '*' --destination-address-prefix '*' --destination-port-range 80 443
az network nsg rule list --resource-group <your-resource-group> --query "[].{Name:name, Access:access, Port:destinationPortRange}"
@unclebean
unclebean / JwtAuthenticationFilter
Last active February 26, 2025 03:12
spring security
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.search.documents.SearchClient;
import com.azure.search.documents.SearchClientBuilder;
import com.azure.search.documents.models.IndexDocumentsBatch;
import com.azure.search.documents.models.IndexDocumentsResult;
import com.azure.search.documents.models.IndexDocumentsAction;
import com.azure.search.documents.models.IndexActionType;
import org.springframework.stereotype.Service;
import java.util.Arrays;
package com.example.service;
import com.azure.search.documents.SearchClient;
import com.azure.search.documents.models.SearchOptions;
import com.azure.search.documents.models.SearchResult;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@unclebean
unclebean / TestVirtualThread.java
Last active February 4, 2025 01:28
tomcat enable virtual thread
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/thread")
public String checkThread() {
@unclebean
unclebean / update helm
Last active January 9, 2025 08:35
helm
# get release name from k8s
kubectl get secrets -n <namespace> | grep sh.helm.release
deploy:
stage: deploy
script:
- export IMAGE_TAG=${CI_COMMIT_TAG:-latest} # Fallback to 'latest' if not set
- sed -i "s/tag:.*/tag: ${IMAGE_TAG}/" values.yaml
- helm upgrade --install my-release my-chart -f values.yaml
@unclebean
unclebean / CustomClaimConverter
Last active December 13, 2024 08:27
EntraId+Graph
import org.springframework.core.convert.converter.Converter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@unclebean
unclebean / crate keystore
Last active December 12, 2024 07:52
certificate
import java.io.FileOutputStream;
import java.io.InputStream;
import java.security.KeyFactory;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
@unclebean
unclebean / CI
Last active November 14, 2024 07:59
pre-install - unzip files
test:
script:
# Find the initdb binary in any subdirectory of /tmp/embedded-pg/ and give it execute permissions
- find /tmp/embedded-pg/ -type f -name "initdb" -exec chmod +x {} \;
- find /tmp/embedded-pg/ -type f -name "initdb" -exec chmod +x {} \;
- ls -l $(find /tmp/embedded-pg/ -type f -name "initdb")
- apt-get update && apt-get install -y sudo
- sudo -u testuser mvn test -Djavax.net.debug=ssl,handshake