# 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
az identity show --name <umi-name> --resource-group <resource-group-name> --query clientId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useCallback} from "react"; | |
export const AllForexPairs = [ | |
{ | |
key: "USD_JPY", | |
label: "USD/JPY", | |
}, | |
{ | |
key: "AUD_USD", | |
label: "AUD/USD", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using PkgTemplates | |
t = Template(user="unclebean", license="MIT", dir="~/code", authors=["unclebean"], plugins=[TravisCI(),Codecov(),Coveralls()]) | |
generate("Project", t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set smartindent | |
set tabstop=4 | |
set shiftwidth=4 | |
set expandtab | |
# very nice vimrc configuration | |
# https://github.com/amix/vimrc |