Skip to content

Instantly share code, notes, and snippets.

@ehizman
ehizman / UsernamePasswordAuthenticationFilter.java
Last active May 10, 2024 07:34
Implementation of a UsernamePassword Authentication Filter
/*
* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ehizman
ehizman / hs_err_pid30080.log
Created June 7, 2023 19:31
A backbones fatal error log
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff9ce8e51f3, pid=30080, tid=20684
#
# JRE version: Java(TM) SE Runtime Environment (17.0.4.1+1) (build 17.0.4.1+1-LTS-2)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0.4.1+1-LTS-2, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# V [jvm.dll+0x7a51f3]
#
server.port=8010
spring.application.name=discoveryservice
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8010/eureka
eureka.instance.ip-address=true
@ehizman
ehizman / TimePlanner.txt
Created November 12, 2022 15:51
Time planner question on Pramp
Time Planner
Implement a function meetingPlanner that given the availability, slotsA and slotsB, of two people and a meeting duration dur, returns the earliest time slot that works for both of them and is of duration dur. If there is no common time slot that satisfies the duration requirement, return an empty array.
Time is given in a Unix format called Epoch, which is a nonnegative integer holding the number of seconds that have elapsed since 00:00:00 UTC, Thursday, 1 January 1970.
Each person’s availability is represented by an array of pairs. Each pair is an epoch array of size two. The first epoch in a pair represents the start time of a slot. The second epoch is the end time of that slot. The input variable dur is a positive integer that represents the duration of a meeting in seconds. The output is also a pair represented by an epoch array of size two.
In your implementation assume that the time slots in a person’s availability are disjointed, i.e, time slots in a person’s availability don’t overlap. Fu
mkdir <project name>
cd <project name>
npm init -y 
npm i -g typescript //install TS globally on your computer

// install express and dotenv globally
  npm install express dotenv

//install type packages for express and node
@ehizman
ehizman / LengthOfLongestSubString.java
Created July 7, 2022 12:53
Sample code to display the longest substring in a string and to return the length of the longest substring in a string.
/**
Coding Step
1. Repeat the question in your own words
2. Do you know the input and output / How do you want to represent your data
3. Ask clarifying questions
4. What edge cases have you thought about
5. What is your approach (the first solution that comes to mind) ⇒ Write out the pseudocode & time & space complexity
6. What is your second approach, **if available** ⇒ Write out the pseudocode & time & space complexity
1. can you come up with something more efficient?
2. can you come up with a different way of solving the problem (doesn't have to be more efficient)?
@ehizman
ehizman / arrayCopy.js
Last active July 6, 2022 11:43
Deep array copy in JS
//copy all values from source to destination
let dest = JSON.parse(JSON.stringify(source));
@ehizman
ehizman / ArraySubSequence.java
Created July 5, 2022 12:56
Obtain all subsequences in an array in java
for (int i = 1; i < size; i++){
List<Integer> subArray = new ArrayList<>();
for(int j = 0; j < array.length; j++){
if (BigInteger.valueOf(i).testBit(j)){
subArray.add(Integer.parseInt(array[j]));
}
}
System.out.println(subArray);
}
@ehizman
ehizman / installing-node-with-nvm.md
Created July 5, 2022 12:53 — forked from d2s/installing-node-with-nvm.md
Installing Node.js to Linux & macOS & WSL with nvm

Installing Node.js with nvm to Linux & macOS & WSL

A quick guide on how to setup Node.js development environment.

Install nvm for managing Node.js versions

nvm allows installing several versions of Node.js to the same system. Sometimes applications require a certain versions of Node.js to work. Having the flexibility of using specific versions can help.

  1. Open new Terminal window.
@ehizman
ehizman / writeFile.js
Created June 22, 2022 01:47
write to files in js
const fs = require("fs");
//write to file sychronously
const dataToWrite = "Hello there by injection";
fs.writeFileSync(`${__dirname}/data.txt`, dataToWrite, "utf-8");
//write to file asynchronously
const dataToWriteAsync = "Hello there by injection async";
fs.writeFile(`${__dirname}/data.txt`, dataToWriteAsync, "utf-8", (err) => {
if (!err) console.log("Done!");