Skip to content

Instantly share code, notes, and snippets.

@Karry
Karry / HttpChunkCache.java
Last active December 15, 2015 16:49
Http chunk cache is designed for sharing part of http response (on top of JBoss Netty) that is identical for many clients. Response have to be send as http/1.1 chunks. As key is used Google proto buffer, but it is simple to rewrite to something different.
/**
* <pre>
* Copyright (c) 2013, AVAST Software a.s.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
@Karry
Karry / BlockParallelIterator.java
Last active December 15, 2015 16:49
Simple iterator for efective parallel iterating huge collections with known count of readers.
/**
* <pre>
* Copyright (c) 2013, AVAST Software a.s.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
/**
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2013 Lukáš Karas <[email protected]>
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
@Karry
Karry / hdmi-monitor.sh
Last active August 22, 2019 22:33
Purpose of this script is to monitor HDMI state on my Raspberry PI and start XBMC / Kodi when output is plugged in and terminate it when it is unplugged. It is tested with Raspbian distribution and XBMC / Kodi compiled from git.
#!/bin/bash
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
## Version 2, December 2004
##
## Copyright (C) 2013 Lukáš Karas <[email protected]>
##
## Everyone is permitted to copy and distribute verbatim or modified
## copies of this license document, and changing it is allowed as long
## as the name is changed.
@Karry
Karry / InfiniteNettyStream.java
Last active August 29, 2015 13:58
Netty example that blocks events from other sockets.
package cz.karry;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioWorkerPool;
import org.jboss.netty.handler.codec.http.*;
import org.jboss.netty.handler.stream.ChunkedInput;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
@Karry
Karry / OrderingExecutor.java
Created October 10, 2014 09:23
Java Executor that warrants task ordering for task with same key. See http://stackoverflow.com/questions/2153663
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.Executor;
/**
* This Executor warrants task ordering for tasks with same key (key have to implement hashCode and equal methods correctly).
*/
public class OrderingExecutor implements Executor{
diff --git a/src/main/java/org/apache/hadoop/hdfs/server/datanode/VolumeBalancer.java b/src/main/java/org/apache/hadoop/hdfs/server/datanode/VolumeBalancer.java
index 59d32ae..7937fbd 100644
--- a/src/main/java/org/apache/hadoop/hdfs/server/datanode/VolumeBalancer.java
+++ b/src/main/java/org/apache/hadoop/hdfs/server/datanode/VolumeBalancer.java
@@ -316,10 +316,7 @@ public class VolumeBalancer {
/*
* Generate the final name of the destination
*/
- final File[] existingSubDirs = findSubdirs(leastUsedBlockSubdir);
-
@Karry
Karry / ScalaJlineNavigation.scala
Last active August 29, 2015 14:17
Scala JLine input with support of navigation using CTRL+arrow
/**
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2015 Lukáš Karas <[email protected]>
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
package io.netty.resolver.dns;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.AddressedEnvelope;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.dns.*;
import io.netty.util.concurrent.Future;
@Karry
Karry / import.log
Created September 6, 2016 22:11
OSMScout import - log from way splitting
+ Step #10 - WayWayDataGenerator...
Module description: Merge ways into bigger ways
Module requires file 'distribution.dat'
Module requires file 'rawways.dat'
Module requires file 'rawturnrestr.dat'
Module provides temporary file 'wayway.tmp'
Module provides temporary file 'turnrestr.dat'
- Generate wayway.tmp...
- Reading type distribution...
- Reading turn restrictions...