Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / WordBoggle.java
Last active February 23, 2024 17:42
Word Boggle
public String[] wordBoggle(char board[][], String[] dictionary)
{
Set<String> doableWords = new HashSet<String>();
for (String word : dictionary) {
if (!doableWords.contains(word)) {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (canMakeWord(i, j, word, 0, board)) {
doableWords.add(word);
}
@LenarBad
LenarBad / ReverseLinkedList.java
Created February 15, 2024 18:22
Reverse linked list
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode current = head;
while(current != null) {
ListNode next = current.next;
current.next = prev;
prev = current;
current = next;
@LenarBad
LenarBad / ReverseLinkedListII.java
Last active February 8, 2024 18:30
Reverse Linked List II. Leetcode 92.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
@LenarBad
LenarBad / MyStack.java
Created February 8, 2024 18:25
Implement Stack using Queues
class MyStack {
private Queue<Integer> q;
public MyStack() {
this.q = new LinkedList();
}
public void push(int x) {
q.add(x);
@LenarBad
LenarBad / MyQueue.java
Created February 8, 2024 18:22
Implement Queue using stacks
class MyQueue {
private Stack<Integer> s1;
private Stack<Integer> s2;
public MyQueue() {
s1 = new Stack<>();
s2 = new Stack<>();
}
public void push(int x) {
@LenarBad
LenarBad / Logger.java
Last active October 21, 2021 16:41
AspectJ. How to log method invocation and print parameters as name:value map from ProceedingJoinPoint for TestNG tests
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.testng.Reporter;
@LenarBad
LenarBad / ReadFileIntoStringGuava.java
Created December 5, 2017 19:44
How to read file into String with Google Guava
public String getFileIntoStringGuava(String fileName) throws IOException {
InputStream input = this.getClass().getResourceAsStream("/" + fileName);
return CharStreams.toString(new InputStreamReader(input, StandardCharsets.UTF_8));
}
@LenarBad
LenarBad / Skip TestNG tests based on condition.java
Last active November 20, 2020 08:49
How to skip TestNG tests based on condition using IInvokedMethodListener
@Listeners(value = ConditionalSkipTestAnalyzer.class)
public class ExampleConditionalSkippingTest {
@NonProduction
@Test
public void test1() { }
@ProductionOnly
@Test
public void test2() { }
@LenarBad
LenarBad / BinaryTreePeers.java
Last active August 8, 2019 01:59
Binary Tree Peers. Everything is public for simplicity
public class Node {
public int value;
public Node left;
public Node right;
public Node peer;
public Node(int value) {
this.value = value;
}
@LenarBad
LenarBad / Heroku - mLab MongoDB - Spring Boot - How to start example StatEntry.java
Last active June 5, 2019 22:09
Heroku - mLab MongoDB - Spring Boot - How to start example
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "stats")
public class StatEntry {
@Id
public String id;