Skip to content

Instantly share code, notes, and snippets.

View bibarsov's full-sized avatar
💭
I may be slow to respond.

Timur bibarsov

💭
I may be slow to respond.
View GitHub Profile
/**
* Please review the class below and suggest improvements. How would
* you refactor this class if it would be in a real-life project?
* There are many problems here, both high-level design mistakes,
* and low-level implementation bugs. We're interested to see high-level
* problems first, since they are most critical. The more mistakes
* you can spot, the better programmer you are.
*/
/**
# netcat; listen on connections on specific port
nc -lvu 5060
# check listening ports
netstat -tulp
# replace in file
sed -i "s+a+b+" filename
public static void main(String[] args) throws UnknownHostException {
TransportClient client = new PreBuiltTransportClient(
Settings.builder().put("cluster.name", "elastic").build()
).addTransportAddress(
new TransportAddress(InetAddress.getByName("localhost"), 9300)
);
MappingElasticsearchConverter elasticsearchConverter = new MappingElasticsearchConverter(
new SimpleElasticsearchMappingContext()
);
DefaultConversionService genericConversionService = new DefaultConversionService();
# Create
docker volume create vol
# Run via volume
docker run ... --mount source=vol,destination=/usr/share/nginx/html ...
# cd into volume folder (osX)
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
[Enter]
cd /var/lib/docker/volumes/vol
# Source
pg_dump -U postgres database | gzip -9 > db.sql.gz
# Target
gunzip db.sql.gz
PGPASSWORD=example psql -U postgres -d database -f db.sql
sudo docker save -o adminer.docker adminer
scp adminer.docker tbibarsov@server:/home/tbibarsov/env/postgres/
sudo docker load -i adminer.docker
@bibarsov
bibarsov / auto_git_file.md
Created February 4, 2020 14:16 — forked from darencard/auto_git_file.md
Automatic file git commit/push upon change

Automatically push an updated file whenever it is changed

Linux

  1. Make sure inotify-tools is installed (https://github.com/rvoicilas/inotify-tools)
  2. Configure git as usual
  3. Clone the git repository of interest from github and, if necessary, add file you want to monitor
  4. Allow username/password to be cached so you aren't asked everytime
git config credential.helper store
@bibarsov
bibarsov / CustomJtwigViewResolverConfigurer.java
Created January 23, 2020 11:21
JTwig support for @path aliases
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jtwig.environment.EnvironmentConfiguration;
import org.jtwig.environment.EnvironmentConfigurationBuilder;
import org.jtwig.escape.config.DefaultEscapeEngineConfiguration;
import org.jtwig.functions.config.DefaultJtwigFunctionList;
import org.jtwig.parser.config.DefaultJtwigParserConfiguration;
@bibarsov
bibarsov / TestRingHandler.java
Created January 21, 2020 10:27
Nginx-Closure Example
import nginx.clojure.java.ArrayMap;
import nginx.clojure.java.NginxJavaRingHandler;
import java.io.IOException;
import java.util.Map;
import static nginx.clojure.MiniConstants.CONTENT_TYPE;
import static nginx.clojure.MiniConstants.NGX_HTTP_OK;
public class TestRingHandler implements NginxJavaRingHandler {
@bibarsov
bibarsov / Snippets.md
Created December 25, 2019 15:20
Spring Boot configuration

Changed to LegacyCookieProcessor because default doesn't allow to use [.second-level-domain.top-level-domain] as a domain for cookie

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> webServerFactoryCustomizer() {
    return tomcatServletWebServerFactory -> tomcatServletWebServerFactory.addContextCustomizers(
        (TomcatContextCustomizer) context -> context.setCookieProcessor(new LegacyCookieProcessor())
    );
}