Skip to content

Instantly share code, notes, and snippets.

View chege-kimaru's full-sized avatar
🏠
Working from home

Kevin Kimaru chege-kimaru

🏠
Working from home
View GitHub Profile
@jpmoura
jpmoura / jest-mock-bcrypt-example.ts
Created August 12, 2021 23:50
Mocking bcrypt library with Jest and TypeScript
// Using compare method as example
const bcryptCompare = jest.fn().mockRejectedValue(new Error('Random error'));
(bcrypt.compare as jest.Mock) = bcryptCompare;
//call method that uses bcrypt.compare with async
const bcryptCompare = jest.fn().mockResolvedValue(true);
(bcrypt.compare as jest.Mock) = bcryptCompare;
//call method that uses bcrypt.compare with async
@chege-kimaru
chege-kimaru / fileuploader.html
Created May 17, 2020 19:41
A sample code on how to upload a file without using form input
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Uploader</title>
<style>
.container {
width: 100%;
height: 100%;
@Schachte
Schachte / LongestSubstringKDistinct.java
Last active April 14, 2024 06:39
Sliding Window Maximum Sum Subarray
import java.util.*;
class LongestSubstringKDistinct {
public static int findLength(String str, int k) {
int windowStart = 0, maxLength = 0;
Map<Character, Integer> charFrequencyMap = new HashMap<>();
for (int windowEnd = 0; windowEnd < str.length(); windowEnd++) {
char rightChar = str.charAt(windowEnd);
charFrequencyMap.put(rightChar, charFrequencyMap.getOrDefault(rightChar, 0) + 1);