Skip to content

Instantly share code, notes, and snippets.

View oyekanmiayo's full-sized avatar
🎯
Focusing

Ayomide Oyekanmi oyekanmiayo

🎯
Focusing
View GitHub Profile
@oyekanmiayo
oyekanmiayo / Makefile-Liquibase
Created May 26, 2020 14:43
Makefile to generate updated liquibase changesets
MIGRATION_LABEL = "change_log_"
# Use NUMBER to seperate change log files and also to make file naming easy
VERSION = "2"
# mvn liquibase:generateChangeLog --changeLogFile=src/main/resources/db/changelogs/change_log_1.yml
makeMigration:
mvn liquibase:diff -DdiffChangeLogFile=src/main/resources/db/changelog/${MIGRATION_LABEL}_${VERSION}.yml
@echo " - include:" >> classpath:db/db.changelog-master.yml
@echo " file: /src/main/resources/db/changelog/$(VERSION)-$(MIGRATION_LABEL).yml" >> classpath:db/db.changelog-master.yml
@oyekanmiayo
oyekanmiayo / BeanUtils-custom.java
Created July 4, 2020 13:59
Omit null values when copying field values from one class to another
BeanUtils.copyProperties(data, entity, getNullPropertyNames(data));
/**
* Ensures that null fields from source are omitted
*/
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for (java.beans.PropertyDescriptor pd : pds) {
//check if value of this property is null then add it to the collection
@oyekanmiayo
oyekanmiayo / BigSort.java
Last active July 9, 2020 11:00
Aptian Contest
/**Big Sorting*/
public class Solution{
static String[] bigSorting2(String[] unsorted) {
Arrays.sort(unsorted, new Comparator<String>() {
public int compare(String n1, String n2) {
if (n1.length() != n2.length()) {
return n1.length() - n2.length(); //Still obeys compares -1 0 1
}
return n1.compareTo(n2);
}
@oyekanmiayo
oyekanmiayo / treasure-hunter.py
Created July 31, 2020 12:50
findtreasure.app hunter
import requests
queue = []
queue.append('https://findtreasure.app/api/v1/games/ileya/e99f8a41-e151-4e81-bf5e-cf2a92229177')
headerx={
'Content-Type' : 'application/json',
'Authorization' : 'Bearer token-here',
'gomoney' : 'phone-number-here'
}
@oyekanmiayo
oyekanmiayo / ValidPalindrome.java
Created August 3, 2020 21:28
Solution to "Valid Palindrome" on Leetcode
class Solution {
public boolean isPalindrome(String s) {
if(s.isEmpty()){
return true;
}
s = s.toLowerCase();
int start = 0;
@oyekanmiayo
oyekanmiayo / EvaluateDivision.java
Created August 3, 2020 21:39
Solution to "Evaluate Division" on Leetcode
public class EvaluateDivision {
public double[] calcEquation(List<List<String>> equations, double[] values, List<List<String>> queries) {
/**
1. Traverse Edge List & Create Ajacency List (Use Map<String, List of Adjs>)
2. Remember going from point A to point B carries a weight, so we need to include that in our adjacent list. So instead of storing just a list of adjacent strings, we can store a list of adjacent Node (class) that will contain the string and weight as fields
3. Remember if A / B = 2.0, then B / A = 1/2.0. So when building the adjacency list, be sure to treat paths as bidirectional, but with weight differences (see first sentence).
4. For each query, try to go from start node to destination node. If possible, get total value, if not possible, answer for that query is -1.0
5. To ensure nodes aren't visited twice for each query, use a set
@oyekanmiayo
oyekanmiayo / DetectCapital.java
Created August 4, 2020 11:27
Solution to "Detect Capital" on Leetcode
class Solution {
public boolean detectCapitalUse(String word) {
if(allCapital(word)){
return true;
}
if(noneCapital(word)){
return true;
}
@oyekanmiayo
oyekanmiayo / AutocompleteSystem.java
Last active August 7, 2020 15:45
Solution to "Design Search Autocomplete System" on Leetcode
class AutocompleteSystem {
TrieNode root;
TrieNode rootCopy;
StringBuilder currSentence;
Map<String, Sentence> sentenceRefs;
/**
* Requirements:
* - Users may input a sentence (each sentence must contain at least one word and end with "#")
@oyekanmiayo
oyekanmiayo / FindMinInArrayII.java
Last active August 9, 2020 06:26
Solution to " Find Minimum in Rotated Sorted Array II" on Leetcode
class Solution {
// Final solution
public int findMin(int[] nums) {
int start = 0;
int end = nums.length - 1;
while(start < end){
int mid = start + (end - start) / 2;
if(nums[mid] < nums[end]){