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
import com.azure.identity.ManagedIdentityCredential;
import com.azure.identity.ManagedIdentityCredentialBuilder;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.credential.AccessToken;
public class AccessTokenFetcher {
public static void main(String[] args) {
// Define the resource you are requesting the token for (e.g., Azure Cognitive Search)
String resource = "https://search.azure.com/";
@unclebean
unclebean / check client id
Last active October 4, 2024 04:03
umi verify aks token
az identity show --name <umi-name> --resource-group <resource-group-name> --query clientId
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder()
.clientId("your-umi-client-id") // User Managed Identity Client ID
.build();
String token = managedIdentityCredential.getToken(
new TokenRequestContext().addScopes("https://ossrdbms-aad.database.windows.net/.default")
).block().getToken();
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*")); // Allow all origins, or specify specific ones
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // Allow all methods
configuration.setAllowedHeaders(List.of("*")); // Allow all headers
configuration.setAllowCredentials(true); // Allow credentials like cookies
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration); // Apply CORS config to all endpoints
@unclebean
unclebean / context.js
Created October 29, 2020 08:36
useContext
import React, {useState, useCallback} from "react";
export const AllForexPairs = [
{
key: "USD_JPY",
label: "USD/JPY",
},
{
key: "AUD_USD",
label: "AUD/USD",
using PkgTemplates
t = Template(user="unclebean", license="MIT", dir="~/code", authors=["unclebean"], plugins=[TravisCI(),Codecov(),Coveralls()])
generate("Project", t)
@unclebean
unclebean / remove_docker_images.sh
Last active October 15, 2019 14:33
remove unused docker images
// remove none image
docker rmi -f $(docker images | grep "<none>" | awk "{print \$3}")
// remove image with dependent child images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
// show stopped container
docker ps --filter "status=exited"
@unclebean
unclebean / sketch-project.md
Last active January 28, 2019 14:52
config for node js

Setup nodejs project

    # initial project
    npm init
    # install unit test dependencies, -D means --save-dev
    npm install -D mocha chai sinon chai-http nyc
    # integrate eslint & prettier & airbnb style guide
    npm install -D eslint prettier
    # peerdeps means to install corresponding airbnb version for eslint
 npx install-peerdeps --dev eslint-config-airbnb
@unclebean
unclebean / java8
Created April 15, 2018 14:20
java features...
java 8
Lambdas
List<Person> people = loadPeolple();
people.sort((p1, p2) -> p1.name.compareTo(p2.name));
// no need final
public UnaryOperator<String> upperCaser(Locale locale) {
return str -> str.toUpperCace(locale);
}
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
# very nice vimrc configuration
# https://github.com/amix/vimrc