Skip to content

Instantly share code, notes, and snippets.

View yp-palF's full-sized avatar

Saurav Mehrotra yp-palF

View GitHub Profile
@yp-palF
yp-palF / config.yml
Created September 17, 2019 04:44
Helm config file for JupyterHub setup
proxy:
secretToken: 3cfc2a39118d182c5f5a4f7206ff5bf158e72bbfac83e8e8b97a4bc908032c7d
void saveToCache(Movie movie) {
List<String> cacheableModel = new ArrayList<>();
String cacheKey;
for (Field field : movie.class.getDeclaredFields()) {
if (field.isAnnotationPresent(Cached.class)) {
field.setAccessible(true);
cacheableModel.add(field.get(movie));
public class HystrixHook extends HystrixCommandExecutionHook {
private HystrixRequestVariableDefault<Integer> hrv = new HystrixRequestVariableDefault<>();
@Override
public <T> void onStart(HystrixInvokable<T> commandInstance) {
HystrixRequestContext.initializeContext();
getThreadLocals();
}
// Buggy code
public class HystrixHook extends HystrixCommandExecutionHook {
private Integer id;
@Override
public <T> void onStart(HystrixInvokable<T> commandInstance) {
getThreadLocals();
}
public class ThreadLocalUtil {
private static ThreadLocal<Integer> idTL = new ThreadLocal<>();
public static void setId(Integer id) {
idTL.set(id);
}
public static void getId() {
idTL.get();
}
Reason Fallback running thread
Fallback from exception On hystrix-thread
Fallback from timeout On hystrix-timer-thread
Fallback on open circuit On calling thread
@yp-palF
yp-palF / main.java
Last active December 29, 2018 20:05
LAMBDA BLOG: Main file with lambda
class BookMyMovie {
public static void main (String[] args) throws Exception {
// List<Movie> movies = List of movies
Filter horrorMovieFilter = (movie) -> movie.getGenre().equals(MovieType.HORROR);
for (Movie movie : movies) {
System.out.println("Movie: " + movie.getName() + " is Horror? " + horrorMovieFilter.isApplicable(movie));
}
}
}
@yp-palF
yp-palF / Movie.java
Last active March 31, 2019 06:03
Lambda BLOG
class Movie {
private MovieType genre;
private Double price;
public MovieType getGenre() { return genre; }
public void setGenre(MovieType genre) { this.genre = genre; }
public Double getPrice() { return price; }
public void setPrice(Double price) { this.price = price; }
enum MovieType {