Skip to content

Instantly share code, notes, and snippets.

@vinaybedre
vinaybedre / DebounceFutureUsage.java
Created January 19, 2021 08:27
DebounceFuture usage in VertX
package com.vinaybedre.vertx.future;
import io.vertx.core.Future;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
@vinaybedre
vinaybedre / DebounceFuture.java
Created January 19, 2021 08:06
Debouncer in VertX
package com.vinaybedre.vertx.future;
import io.vertx.core.Future;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
@vinaybedre
vinaybedre / assertSorted.java
Last active November 11, 2020 15:55
assertSorted: Check if your Java list of objects is sorted per a property (mostly useful in unit tests)
import java.util.Comparator;
import java.util.function.Function;
import java.util.List;
class TestUtil {
public static <T, U> boolean assertSorted(
List<T> list, Function<T, U> fieldExtractor, Comparator<U> comparator) {
if (list.isEmpty()) {
return true;
}
@vinaybedre
vinaybedre / schema.graphqls
Created April 13, 2020 03:58
Reviews GraphQL Schema
type Review @key(fields: "id") {
id: ID!
body: String
author: User @provides(fields: "username")
product: Product
}
type User @key(fields: "id") @extends {
id: ID! @external
username: String @external
@vinaybedre
vinaybedre / GraphQLConfig.java
Created April 13, 2020 03:56
GraphQLConfig for Product
package com.vinaybedre.gqlfederation.product;
import com.apollographql.federation.graphqljava.Federation;
import com.apollographql.federation.graphqljava._Entity;
import com.coxautodev.graphql.tools.SchemaParser;
import graphql.schema.GraphQLSchema;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@vinaybedre
vinaybedre / jest-debug-all.json
Created May 7, 2019 12:42
launch.json to debug all jest unit tests in Visual Studio Code
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
@vinaybedre
vinaybedre / debug-curr-ts-file.json
Created May 7, 2019 12:41
launch.json to debug currently opened TS file in Visual Studio Code
{
"name": "Current TS File",
"type": "node",
"request": "launch",
"args": ["${relativeFile}"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
}
@vinaybedre
vinaybedre / ArrayforEachCustom.js
Last active June 6, 2018 06:33
Custom polyfill for Array in Javascript
Array.prototype.forEachCust = function (func) {
for (let i = 0; i < this.length; i++) {
console.log(`Custom forEach for Array`);
func(this[i], //The current array element
i, //The current array element's index
this); //The current array
}
}
let arr = [1, 2, 3];
//ArrayFlatter, flatens array of any nested levels
var arrayFlatter = function(){
/**
* Method to flatten input array.
* @param {string} input - Input array, containing deeply nested array
*/
this.flatArray = function(input){
return new Array(JSON.stringify(input).replace(/[\[\]]/g,""));
}