Skip to content

Instantly share code, notes, and snippets.

View alexeyryzhikov's full-sized avatar

Alexey Ryzhikov alexeyryzhikov

View GitHub Profile
@alexeyryzhikov
alexeyryzhikov / ConsistentHashingTest.java
Created April 13, 2016 14:06
Consistent hashing test
import java.util.Collection;
import java.util.Map;
import org.elasticsearch.common.collect.ArrayListMultimap;
import org.elasticsearch.common.collect.Multimap;
import org.elasticsearch.common.hash.Hashing;
import org.junit.Test;
public class ConsistentHashingTest {
@alexeyryzhikov
alexeyryzhikov / BufferedReader.java
Last active April 8, 2016 13:52
NIO to IO bridge for BufferedReader
public class BufferedReader extends Reader {
private static final int BUFFER_CAPACITY = 64 * 1024; //64k
private List<CharBuffer> buffers = new ArrayList<>();
private int bufferIdx = 0;
public BufferedReader() {
this.buffers = new ArrayList<>();
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do \
echo $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB \
$(docker ps | grep $line | awk '{printf $NF" "}') ; \
done | sort -n
@alexeyryzhikov
alexeyryzhikov / release-prepare,sh
Last active August 29, 2015 14:19
Prepare maven project for a release by removing -SNAPSHOT version suffix
VER=0.0.1 grep -lRZ --include *.xml $VER-SNAPSHOT . | xargs -0 -l sed -i -e s/$VER-SNAPSHOT/$VER/
VER=0.0.1 grep -lRZ --include *.conf $VER-SNAPSHOT . | xargs -0 -l sed -i -e s/$VER-SNAPSHOT/$VER/
@alexeyryzhikov
alexeyryzhikov / proxy_context
Created April 23, 2015 05:41
Proxy with contexts
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name demo.com;
location = / {
@alexeyryzhikov
alexeyryzhikov / gist:ce7b9a6def9574247b87
Last active August 29, 2015 14:17
Test Log4j output to console
@BeforeClass
public static void setupTestClass() {
ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "%d [%p] %c - %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.TRACE);
console.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
@alexeyryzhikov
alexeyryzhikov / AsyncServer.java
Created December 2, 2014 18:05
NIO Async Server basics
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.CountDownLatch;
@alexeyryzhikov
alexeyryzhikov / tablesize.sql
Created November 28, 2014 07:13
MySQL table sizes
SELECT
table_schema,
table_name,
SUM(data_length + index_length)/1024/1024 AS size
FROM information_schema.tables
GROUP BY table_schema, table_name
ORDER BY 3 DESC;
@alexeyryzhikov
alexeyryzhikov / gist:6351556
Created August 27, 2013 09:36
Size of the directories in the current directory
du -sh ./*
SELECT *
FROM v$locked_object l, dba_objects o
WHERE l.object_id = o.object_id
ORDER BY o.object_id, 1 desc