Skip to content

Instantly share code, notes, and snippets.

View trustin's full-sized avatar
🌄
▂▃▅▇█▓▒░۩۞۩░▒▓█▇▅▃▂

Trustin Lee trustin

🌄
▂▃▅▇█▓▒░۩۞۩░▒▓█▇▅▃▂
View GitHub Profile
package socket.proxy;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.Queue;
public void inboundBufferUpdated(ChannelHandlerContext ctx) {
Queue<MyMessage> in = ctx.inboundMessageBuffer();
Queue<MyNewMessage> out = ctx.nextInboundMessageBuffer();
for (;;) {
MyMessage m = in.poll();
if (m == null) {
break;
}
MyNewMessage decoded = decode(m);
out.add(decoded);
// No more dynamicBuffer() - use buffer().
ByteBuf buf = ByteBuf.buffer();
// Increase the capacity of the buffer.
buf.capacity(1024);
...
// Decrease the capacity of the buffer (the last 512 bytes are deleted.)
buf.capacity(512);
// Before:
ServerBootstrap b = new ServerBootstrap();
try {
b.eventLoop(new NioEventLoop(), new NioEventLoop()); // <-- HERE
...
} finally { b.shutdown(); }
// After:
ServerBootstrap b = new ServerBootstrap();
try {
#!/bin/bash
if [[ $# -lt 0 ]] || [[ $# -gt 2 ]]; then
echo "Usage: $0 <pull request id> [<directory>]"
fi
PULL_REQ_ID="$1"
if [[ "x$2" != 'x' ]]; then
cd "$2" || exit 1
$ git config alias.merge-pullreq '!git-merge-pullreq'
$ git merge-pullreq 1234
Fetching the pull request 1234 from netty/netty ..
Running: git am /tmp/pullreq.XXXXXXXX
Applying: ...
@trustin
trustin / private.xml
Created November 13, 2012 02:32
Trustin's KeyRemap4MacBook configuration
<?xml version="1.0"?>
<root>
<appdef>
<appname>PATHFINDER</appname>
<equal>com.cocoatech.PathFinder</equal>
</appdef>
<item>
<name>Change Shift+Space to Command+Space</name>
<identifier>private.shiftspace_to_cmdspace</name>
@trustin
trustin / pf.conf
Created November 15, 2012 06:52
Trustin's /etc/pf.conf for Mac OS X
# 1. Put this file to /etc/pf.conf
# 2. Install init boot scripts using IceFloor then - http://www.hanynet.com/icefloor/
# I tried to use IceFloor to configure everything but it didn't work very well.
# 3. Once done, you can confirm the rules were loaded with 'sudo pfctl -sr'
# 4. At System Preferences -> Security -> Firewall -> Firewall Options,
# check 'Block all incoming connections' to prevent annoying per-app dialogs.
set skip on lo0
set block-policy drop
@trustin
trustin / gist:4081911
Last active October 12, 2015 20:18
Trustin's CrashPlan exclusion regular expressions for Mac OS X (crashplan)
/Users/[^/]+/.*(~|\.(log|tmp|bak|lock))
/Users/[^/]+/\.(bash_history|scala_history|mysql_history|lesshst)
/Users/[^/]+/\.m2/repository/.*
/Users/[^/]+/\.ivy2/(cache|local)/.*
/Users/[^/]+/Library/Application Support/(Firefox|Thunderbird)/.*
/Users/[^/]+/[Ww]orkspaces?/.*/target/.*
/Users/[^/]+/[Ww]orkspaces?/openjdk/(sources|OBF_DROP_DIR)/.*
/Users/[^/]+/[Vv]irtualization/[^/]+\.vmwarevm/.*
/Users/[^/]+/[Ss]3/.*
/Users/backup/.*
$ cat ~/.local/bin/simple-httperf
#!/bin/bash
if [[ $# -ne 6 ]]; then
echo "Usage: $0 <num_conns> <num_reqs_per_conn> <burst_len> <host> <port> <path>"
exit 1
fi
exec httperf --num-conns "$1" --num-calls "$2" --burst-length "$3" --server "$4" --port "$5" --uri "$6" --rate 10000000