Skip to content

Instantly share code, notes, and snippets.

View Deviad's full-sized avatar

Davide P. Deviad

View GitHub Profile
@Deviad
Deviad / Solution.java
Last active February 4, 2023 23:11
Cheapest Flights Within K Stops
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
/*
Fixed, clear solution which I have created after studying the problem that works in the expected time
on Leetcode and is easy to understand and remember
*/
class Solution {
@Deviad
Deviad / GetYourGuide.java
Last active January 27, 2023 18:27
Interviews in Switzerland
package com.adobe.prep;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
public class GetYourGuide {
public static void main(String[] args) {
String s = "photo.jpg, Warsaw, 2013-09-05 14:08:15\n" +
/*
This did not work because of an issue which I couldn't investigate further with the loop:
for (int i = 'a'; i < 'z'; i++) {
TrieNode child = curr.node.children.get((char) (i));
if (child != null) {
queue.offer(new Pair(curr, (char) (i), child));
}
}
I changed this in Solution2
*/
@Deviad
Deviad / BruteCollinearPoints.java
Last active May 11, 2022 17:20
Collinear Points
package week3.assignment;
import edu.princeton.cs.algs4.Queue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
@Deviad
Deviad / CheckinsControllerSpec.groovy
Created July 14, 2021 10:53
Example of a hand made mock in micronaut
package com.projectcheckins
import com.projectcheckins.core.CheckinsRepository
import com.projectcheckins.core.UserCheckins
import io.micronaut.context.annotation.Replaces
import io.micronaut.context.annotation.Requires
import io.micronaut.core.annotation.NonNull
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
@Deviad
Deviad / EntityAnnotationMapperSpec.groovy
Last active July 13, 2021 09:36
Micronaut Index Annotation Test
/*
* Copyright 2017-2020 original authors
*
* 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
package con.worldpay.syscon;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
@Deviad
Deviad / Program.java
Last active May 6, 2021 06:36
Iterative solution to find nodes at distance k from another one
// My solution (it passes 7 tests out of 10)
import java.util.*;
class Program {
// This is an input class. Do not edit.
static class BinaryTree {
public int value;
public BinaryTree left = null;
public BinaryTree right = null;
@Deviad
Deviad / MapContainer.ts
Last active May 10, 2020 14:07
google-maps-react not working
import React, {useState} from 'react';
import {GoogleAPI, GoogleApiWrapper, Map, Marker} from 'google-maps-react'
import {render} from "react-dom";
interface MapContainerProps {
google: GoogleAPI;
}
type MarkerEntry = { key: string, title: string, name: string, position: { lat: number, lng: number } };
const markers: MarkerEntry[] = [
@Deviad
Deviad / Geolocalization.java
Last active May 3, 2020 10:34
Get coords from Google and use them to create address entity and then save a new user
Mono<GeocodingResponseDto> personalAddressGeo = bundle.getGeocodingClient().getGeocoding(URLEncoder.encode(requestDTO.getPersonalAddress().getFirstLine(), StandardCharsets.UTF_8.toString()), apiKey);
Mono<GeocodingResponseDto> companyAddressGeo = bundle.getGeocodingClient().getGeocoding(URLEncoder.encode(requestDTO.getCompanyAddress().getFirstLine(), StandardCharsets.UTF_8.toString()), apiKey);
return personalAddressGeo
.subscribeOn(Schedulers.immediate())
.flatMap(this::handleNotFound)
.doOnNext(x -> {
requestDTO.getPersonalAddress().setLat(x.getLocation().getLat());
requestDTO.getPersonalAddress().setLon(x.getLocation().getLon());
})