Skip to content

Instantly share code, notes, and snippets.

@willmenn
willmenn / Permutation.java
Created July 24, 2020 13:11
Permutation in java
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res= new ArrayList();
permute(nums, 0, res);
return res;
}
public static int[][] permute(int[] arr, int index, List<List<Integer>> res){
if (index == arr.length){
List<Integer> r = new ArrayList();
for(int num: arr){
@willmenn
willmenn / JWT.java
Created June 12, 2019 09:44
JWT implementation in java
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
String header = "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
String payload = "{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}";
String headerBase64 = Base64.encodeBase64URLSafeString(header.getBytes());
String payloadBase64 = Base64.encodeBase64URLSafeString(payload.getBytes());
//Create a secret to create the signature
String secret = "your-256-bit-secret"; //this could be anything
@willmenn
willmenn / Main.java
Created March 28, 2019 06:59
RxJava Fanout with network request
public static void main(String[] args) {
int threadCount = Runtime.getRuntime().availableProcessors();
System.out.println("Thread Count:" + threadCount);
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
Scheduler scheduler = Schedulers.from(executorService);
Observable.fromArray(buildNetworkUriCalls("oi").toArray())
.flatMap(url -> getNetworkFutureAndObservable(url)
.subscribeOn(scheduler)
@willmenn
willmenn / Readme.md
Last active September 6, 2018 14:09
How to Stop all the Docker containers at once

I found this in the internet, and I want to share, because sometimes we have a lot of containers in place and we need to stop them, the command for that is this one:

$ docker kill $(docker ps -q)

@willmenn
willmenn / checkstyle.gradle
Created August 7, 2018 01:54
Gradle Checkstyle with threshold of errors.
tasks.withType(Checkstyle).each { checkstyleTask ->
checkstyleTask.doLast {
reports.all { report ->
def errors = 0
def threshold = 1
def outputFile = report.destination
outputFile.text.eachLine {
if (it.contains("<error ")) {
errors++
}
@willmenn
willmenn / Readme.md
Last active August 17, 2018 18:39
Intellij configuration to be used by gradle idea pllugin

To use this configuration you will need to have the idea gradle plugin installed on your build.gradle and import this file.

This file will add in your project the following configuration:

  • Enable annotation process <- for Lombok
  • Enable Gradle Auto-Import
  • Enable optmize imports
  • Configure Spring plugin
  • Enable Intellij to create Empty Content Root Dirs for Gradle (create directories for empty content roots automatically)
@willmenn
willmenn / gist:d3aaa5618d2d7e7858ede6ac089821b7
Last active August 7, 2018 01:55
IntelliJ 2018.1 Gradle Settings to createEmptyContentRootDirectories
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
@willmenn
willmenn / RxJavaMultipleArrays.java
Created October 15, 2017 16:57
RxJava Multiples Threads to process a List
package com.willmenn.rxjava;
import org.springframework.util.StopWatch;
import rx.Observable;
import rx.Scheduler;
import rx.schedulers.Schedulers;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@willmenn
willmenn / V1_1__MigrationExample.java
Last active March 9, 2017 22:14
Flyway with Multiples Schemas
package db.migration;
import org.flywaydb.core.api.configuration.ConfigurationAware;
import org.flywaydb.core.api.configuration.FlywayConfiguration;
import org.flywaydb.core.api.migration.spring.SpringJdbcMigration;
import org.springframework.jdbc.core.JdbcTemplate;
public class V1_1__MigrationExample implements SpringJdbcMigration, ConfigurationAware {
@willmenn
willmenn / BootstrapApp.java
Last active June 29, 2016 23:55
How to bootstrap java application with Jetty java configuration
public class BootstrapApp {
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
addContextPath(context);
addServlets(context);
addFilters(context);
buildAndStartServer(context);