Skip to content

Instantly share code, notes, and snippets.

View paulwellnerbou's full-sized avatar

Paul Wellner Bou paulwellnerbou

View GitHub Profile
View CreateMultiCache.js
const createMultiCache = async (cachePromises) => {
return Promise.all(cachePromises).then(caches => multiCaching(caches));
}
View CreateRedisCache.js
import { caching } from 'cache-manager';
import { redisStore } from 'cache-manager-redis-yet';
async function createRedisCache(redisHost, ttl) {
const redisConfig = { url: `redis://${redisHost}`, db: 0, ttl };
const redisCacheStore = await redisStore(redisConfig);
return caching(redisCacheStore);
}
View CreateCache.js
import { caching, multiCaching } from 'cache-manager';
import { redisStore } from 'cache-manager-redis-yet';
function createMemoryCache(max, ttl) {
return caching('memory', { max, ttl });
}
async function createRedisCache(redisHost, ttl) {
const redisConfig = { url: `redis://${redisHost}`, db: 0, ttl };
const redisCacheStore = await redisStore(redisConfig);
View CacheWrapper.js
import { NoCacheableError, redisStore } from 'cache-manager-redis-yet';
const cachePromise = createCache(); // this method is creating the actual cache promise object (see other code snippets)
const CacheWrapper = {
get: async (key) => {
if (cachePromise) {
const cache = await cachePromise;
return cache.get(key);
}
@paulwellnerbou
paulwellnerbou / docker-compose.yml
Created July 1, 2021 06:10
Docker Compose file to start OpenProject with HTTPS support
View docker-compose.yml
version: "3.7"
# this file is taken from https://github.com/opf/openproject-deploy/blob/stable/11/compose/docker-compose.yml, replaced
# the apache proxy with jwilder/nginx-proxy and the companion enabling ssl support
networks:
frontend:
backend:
volumes:
pgdata:
View prepare-machine.sh
# Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable edge"
apt-get install -y docker-ce
sudo usermod -aG docker ubuntu
# Install Docker Compose
curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
View YourSolrContext.java
package de.wellnerbou.solr;
import de.wellnerbou.solr.CollectionAwareEntityInformationFacade;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.core.SolrTemplate;
View Repository.java
package de.wellnerbou.solr;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.SolrOperations;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.query.SolrEntityInformation;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
public class YourRepository extends SimpleSolrRepository<YourSolrDocument, String> {
View CollectionAwareEntityInformationFacade.java
package de.wellnerbou.solr;
import org.springframework.data.solr.core.mapping.SimpleSolrMappingContext;
import org.springframework.data.solr.repository.query.SolrEntityInformation;
import org.springframework.data.solr.repository.support.SolrEntityInformationCreatorImpl;
public class CollectionAwareEntityInformationFacade<T, ID> implements SolrEntityInformation<T, ID> {
private SolrEntityInformation<T, ID> solrEntityInformation;
private String collectionName;
@paulwellnerbou
paulwellnerbou / example.java
Last active October 8, 2018 08:45
Code Examples Apache Commons Configuration2 Documentation
View example.java
/*
* First example from https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html#Reloading_File-based_Configurations
*/
Parameters params = new Parameters();
// Read data from this file
File propertiesFile = new File("config.properties");
ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)