Skip to content

Instantly share code, notes, and snippets.

View ashwinrs's full-sized avatar
💭
🍦

Ashwin S ashwinrs

💭
🍦
View GitHub Profile
@ashwinrs
ashwinrs / impersonate_sa.sh
Created August 3, 2020 21:12
How to run CLI command as a Google service account
# download service account key (this will require ServiceAccount Key Admin role)
gcloud iam service-accounts keys create ./key.json --iam-account <service_account>
# Set following env var to point to the service account key file
export GOOGLE_APPLICATION_CREDENTIALS=./key.json
# Keep in mind that changing gcloud auth by the below command, will not work as only "gcloud" commands use it,
# gcloud auth activate-service-account <service_account> --key-file=./key.json
# gcloud auth list
@ashwinrs
ashwinrs / .bash_kube.sh
Created January 3, 2020 16:51
Kubernetes aliases
alias k='kubectl'
alias kx='kubectx'
alias khelp='echo n:nodes, p:pods, s:services, d: deployment, con:context, i:ingress, ns:namespace, map:configmaps, sec:secret, roll:rollout, kx=kubectx'
### Drop into an interactive terminal on a container
alias kexec='f() { kubectl exec -it "$@" -- bash; }; f'
### Pod management.
alias kp='kubectl get pods'
alias kpwatch='kubectl get pods --watch'
alias kpwide='kubectl get pods -o wide'
@ashwinrs
ashwinrs / randomString.sh
Created June 25, 2018 18:33
Generate a random string
head -n 4096 /dev/urandom | openssl sha1
@ashwinrs
ashwinrs / example.ts
Created May 17, 2018 22:04
Function signature with return type in typescript
// This function takes two params and returns a variable of type Immutable.Map<String, any>.
// Function is just for explaining the format of a function in typescript. Functionally this function does not do anything :)
// param1 : Type is Immutable.Map<String, any>
// param2 : Type is number
// returns a value of type Immutable.Map<Strin, any>
const functionVar = (param1: Immutable.Map<String, any>, param2: number): Immutable.Map<String, any> => {
return state;
};
@ashwinrs
ashwinrs / AddAProperty.js
Created May 9, 2018 23:54
Add a new property to an object when creating a new object
/*
arrOfObj = [{"name":"Ash"},{"name":"tim"},{"name":"david"}]
*/
var result = arrOfObj.map(function(el) {
var o = Object.assign({}, el);
o.isActive = true;
return o;
})
console.log(result)
@ashwinrs
ashwinrs / build.gradle
Created March 28, 2018 21:32
How to include local jars in build.gradle
dependency {
compile files ("../../x/y/z/libs/abs.jar")
}
@ashwinrs
ashwinrs / build.gradle
Last active February 2, 2018 02:17
Finding dependency tree in gradle build system
// https://stackoverflow.com/a/41784667/437894
apply plugin: 'project-report'
@ashwinrs
ashwinrs / IterateOverJSONUsingGson.java
Last active January 9, 2023 23:54
Iterate over elements in a JSON using GSON in Java
final JsonObject jsonObject = GSON.toJsonTree(<Object>).getAsJsonObject();
for(Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
System.out.println("Key = " + entry.getKey() + " Value = " + entry.getValue() );
}
@ashwinrs
ashwinrs / PrettyPrintJSON.java
Created February 1, 2018 22:03
Pretty Print a JSON in Java
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(GSON.toJson(<Object>));
String prettyJsonString = gson.toJson(je);
System.out.println(prettyJsonString);
@ashwinrs
ashwinrs / EnumUtils.java
Created December 13, 2017 18:08
Gets enum from a string
/**
* A common method for all enums since they can't have another base class
* @param <T> Enum type
* @param c enum type. All enums must be all caps.
* @param string case insensitive
* @return corresponding enum, or null
*/
public static <T extends Enum<T>> T getEnumFromString(Class<T> c, String string) {
if( c != null && string != null ) {
try {