Skip to content

Instantly share code, notes, and snippets.

View jutikorn's full-sized avatar

EddieJ jutikorn

  • Bangkok, Thailand
View GitHub Profile
@jutikorn
jutikorn / boyer_moore_search.py
Created February 26, 2023 14:44
Remove unused drawable in Android project, using Boyer Moore pattern matching algorithm (Bad Character Heuristic)
# Boyer Moore
# Python3 Program for Bad Character Heuristic
# of Boyer Moore String Matching Algorithm
# https://www.geeksforgeeks.org/boyer-moore-algorithm-for-pattern-searching/
NO_OF_CHARS = 256
def badCharHeuristic(string, size):
'''
The preprocessing function for
def read_file_line_by_line(filename, pattern):
if not filename.endswith('.kt') and not filename.endswith('.java') and not filename.endswith('.xml'):
print(f' Invalid file. filename is {filename}')
return
try:
with open(filename, 'r', encoding='UTF-8') as file:
while (line := file.readline().rstrip()):
print(line)
class Solution {
private static final int[][] directions = new int[][] {
{0, 1},
{1, 0},
{-1, 0},
{0, -1}
};
public int shortestPath(int[][] grid, int k) {
int TARGET_ROW = grid.length -1;
@jutikorn
jutikorn / Solution.java
Created October 20, 2022 14:37
Permutation
// https://leetcode.com/problems/permutations/
class Solution {
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> ans = new ArrayList();
if(nums == null || nums.length == 0) return ans;
ans.add(new ArrayList());
for(int i = 0; i < nums.length; i++) {
int size = ans.size();
@jutikorn
jutikorn / gist:effd598e18975e21d9994a921d0155a5
Created July 23, 2022 09:16
Longest Substring with Same Letters after Replacement
import java.util.*;
class StringPermutation {
// obdbcaf
public static boolean findPermutation(String str, String pattern) {
int left = 0;
int patternLength = pattern.length();
HashMap<Character, Integer> map = new HashMap();
for(int i = 0; i < pattern.length(); i++){
@jutikorn
jutikorn / KSumWithBug.java
Created June 29, 2022 00:55
still it doesn't prevent the edge case when nums = [1,1,1,1], target = 4
class Solution {
private List<List<Integer>> result = new ArrayList();
public List<List<Integer>> fourSum(int[] nums, int target) {
Arrays.sort(nums);
List<Integer> previousNum = new ArrayList();
kSum(previousNum, nums, 4, 0, target);
return result;
}
@jutikorn
jutikorn / Activities.kt
Created January 5, 2021 04:07
3 Activities, 3 AndroidEntryPointes, using ActivityRetainedScoped
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject
lateinit var emailSender: EmailSender
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
println("From $this EmailSender is $emailSender")
@jutikorn
jutikorn / CodeGen.java
Last active January 5, 2021 04:08
Only 1 AndroidEntryPoint and use ActivityRetainedScoped
private EmailSender getEmailSender() {
Object local = emailSender;
if (local instanceof MemoizedSentinel) {
synchronized (local) {
local = emailSender;
if (local instanceof MemoizedSentinel) {
local = new EmailSender();
emailSender = DoubleCheck.reentrantCheck(emailSender, local);
}
}
class MainFragment: Fragment(){
...
...
...
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel._onActivityCreated.call()
}
...
...
@MainThread
public static <X, Y> LiveData<Y> map(@NonNull LiveData<X> source,
@NonNull final Function<X, Y> func) {
final MediatorLiveData<Y> result = new MediatorLiveData<>();
result.addSource(source, new Observer<X>() {
@Override
public void onChanged(@Nullable X x) {
result.setValue(func.apply(x));
}
});