This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Chart from 'stimulus-chartjs' | |
| // Connects to data-controller="async-chart" | |
| export default class extends Chart { | |
| static values = { | |
| url: String | |
| } | |
| connect() { | |
| fetch(this.urlValue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ExternalApiRuntime | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def log_process_action(payload) | |
| messages = super | |
| api_runtime = payload[:api_runtime] | |
| messages << (format('ExternalAPI: %.1fms', api_runtime.to_f)) if api_runtime | |
| messages | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Controller } from '@hotwired/stimulus' | |
| import { TempusDominus } from '@eonasdan/tempus-dominus' | |
| function findParentBySelector(element, selector) { | |
| while (element && element.parentElement) { | |
| if (element.parentElement.matches(selector)) { | |
| return element.parentElement; | |
| } | |
| element = element.parentElement; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def cross_correlation(x, y): | |
| # Calculate cross-correlation using convolution | |
| ccf_values = np.convolve(x, y[::-1], mode='full') / np.sum(y**2) | |
| # Adjust indices to represent lags | |
| lags = np.arange(-(len(y) - 1), len(x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pkg_resources import working_set | |
| def lambda_handler(event, context): | |
| print(*(f'{m.key}~={m.version}' for m in sorted(working_set, key=lambda x: x.key)), sep='\n') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class VertxRetryHelper { | |
| private static final Logger LOG = LoggerFactory.getLogger(VertxRetryHelper.class); | |
| private final Vertx vertx; | |
| public VertxRetryHelper(Vertx vertx) { | |
| this.vertx = vertx; | |
| } | |
| public <T> Supplier<CompletionStage<T>> decorateCompletionStage( | |
| RateLimiter rateLimiter, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyVerticle extends AbstractVerticle { | |
| /* Try to acquire permits asynchronously */ | |
| private <T> Supplier<CompletionStage<T>> decorateCompletionStage( | |
| RateLimiter rateLimiter, | |
| Supplier<CompletionStage<T>> supplier) { | |
| return () -> { | |
| final CompletableFuture<T> promise = new CompletableFuture<>(); | |
| final BiConsumer<T, Throwable> biConsumer = (result, throwable) -> { | |
| if (throwable != null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| import os | |
| def cache_to_pickle(cache_dir): | |
| def decorator(func): | |
| def wrapper(*args, **kwargs): | |
| # Generate a unique cache filename based on the function and its arguments | |
| cache_filename = f"{func.__name__}_{hash((args, tuple(kwargs.items())))}.pickle" | |
| cache_path = os.path.join(cache_dir, cache_filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cache_disk(seconds = 900, cache_folder="/tmp"): | |
| def doCache(f): | |
| def inner_function(*args, **kwargs): | |
| # calculate a cache key based on the decorated method signature | |
| key = sha1(str(f.__module__) + str(f.__name__) + str(args) + str(kwargs)).hexdigest() | |
| filepath = os.path.join(cache_folder, key) | |
| # verify that the cached object exists and is less than $seconds old | |
| if os.path.exists(filepath): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.fasterxml.jackson.core.JsonParser; | |
| import com.fasterxml.jackson.databind.DeserializationContext; | |
| import com.fasterxml.jackson.databind.JsonDeserializer; | |
| import com.fasterxml.jackson.databind.module.SimpleModule; | |
| import java.io.IOException; | |
| public class EmptyStringToNullDeserializer extends JsonDeserializer<String> { | |
| @Override | |
| public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { | |
| String value = jsonParser.getValueAsString(); |