Skip to content

Instantly share code, notes, and snippets.

@kjunine
kjunine / Main.java
Created August 2, 2012 06:52
Gist Test
package gisttest;
public static void main(String[] args) {
System.out.println("Gist test");
}
@kjunine
kjunine / NamedThreadFactory.java
Created August 9, 2012 03:48
Changing thread names of Netty threads
package swiftify.channel.util.execute;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
public class NamedThreadFactory implements ThreadFactory {
private final String name;
private final AtomicInteger index = new AtomicInteger(1);
public NamedThreadFactory(String name) {
@kjunine
kjunine / InsightQuize01.java
Created September 1, 2012 11:00
Rotate array without copy
package net.kjunine.insightquiz;
import java.util.Arrays;
public class InsightQuiz01 {
public static void rotateArray(int[] array, int s, int t, int k) {
int start = s;
int length = t - s + 1;
int offset = k;
@kjunine
kjunine / install.sh
Created September 13, 2012 00:26 — forked from padcom/install.sh
Gitorious installation on Ubuntu 12.04
#!/bin/bash
#------------------------------------------------------------------------------
# SETTINGS
#------------------------------------------------------------------------------
MYSQL_ROOT_PASSWORD=password
MYSQL_GITORIOUS_PASSWORD=password
GITORIOUS_HOST=gitorious
SYSADMIN=sysadmin
@kjunine
kjunine / DelimiterAppender.java
Created October 21, 2012 11:09
DelimiterAppender
import static org.jboss.netty.buffer.ChannelBuffers.*;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
public class DelimiterAppender extends OneToOneEncoder {
@kjunine
kjunine / Handler.java
Created October 22, 2012 09:56
Using ChannelGroup to close all connected channel
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
this.channel = e.getChannel();
channels.add(channel);
}
@kjunine
kjunine / WebSocketServer.java
Created October 22, 2012 10:00
Web Socket Server Handler
public class WebSocketServer {
private final InetSocketAddress localAddress;
private final ServerBootstrap bootstrap;
public WebSocketServer (InetSocketAddress localAddress) {
this.localAddress = localAddress;
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new NamedThreadFactory(
@kjunine
kjunine / SortedProperties.java
Created October 23, 2012 08:18
sorted properties
import java.util.Collections;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
@SuppressWarnings("serial")
public class SortedProperties extends Properties {
@SuppressWarnings({ "rawtypes", "unchecked" })
public synchronized Enumeration keys() {
@kjunine
kjunine / FileLister.java
Created November 22, 2012 08:17
File Lister
package sample.filelist;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class FileLister {
@kjunine
kjunine / AdditionalAssert.java
Created December 12, 2012 09:48
Asserts exception without try-catch or @Test.expected() in junit.
package net.kjunine.test;
import static org.junit.Assert.*;
import java.io.IOException;
import org.junit.Test;
public class AdditionalAssert {