Skip to content

Instantly share code, notes, and snippets.

@need4spd
need4spd / gist:4450182
Last active June 15, 2020 12:32
lucene 3.6 term freq
package com.tistory.devyongsik.termFrequency;
import java.io.IOException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
@need4spd
need4spd / Consumer.java
Created November 29, 2012 00:39
[Java] BlockingQueue를 사용한 생산자-소비자 패턴 모델 구현
package blockingqueue;
import java.util.concurrent.BlockingQueue;
public class Consumer implements Runnable {
private BlockingQueue queue;
public Consumer(BlockingQueue queue) {
this.queue = queue;
@need4spd
need4spd / hash.pl
Created November 28, 2012 23:08
perl hash
my %rule = (1=>2, 2=>3, 3=>5, 4=>7, 5=>11, 6=>13, 7=>17);
foreach my $k (keys %rule) {
print "$rule{$k}";
}
@need4spd
need4spd / 1.pl
Created November 29, 2012 00:54
[Perl] Date연산
#!/usr/bin/perl
use DateTime;
use strict;
use warnings;
my $start_date = DateTime->new(
year=>1901,
month=>1,
day=>1,
@need4spd
need4spd / 1.rb
Created November 29, 2012 00:54
[Ruby] Date연산
require 'date'
startDate=Date.new(1901,1,1)
endDate=Date.new(2000,12,31)
startDate === endDate #비교, =가 3개
startDate.wday == 0 #요일, 0이 일요일
startDate.mday == 1 #month of day
startDate = startDate + 1 #하루 증가
@need4spd
need4spd / TestPool.java
Last active February 13, 2019 14:21
TestPool
import org.apache.commons.pool2.impl.GenericObjectPool;
public class TestPool {
public static void main(String[] args) throws Exception {
for(int i = 0; i < 10; i++) {
GenericObjectPool genericObjectPool = new GenericObjectPool(new MyPoolableObjectFactory());
MyPoolableObject obj = (MyPoolableObject)genericObjectPool.borrowObject();
System.out.println("i : " + i);
@need4spd
need4spd / MyPoolableObjectFactory.java
Created February 13, 2019 14:20
MyPoolableObjectFactory
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
public class MyPoolableObjectFactory extends BasePooledObjectFactory<MyPoolableObject> {
@Override
public MyPoolableObject create() {
return new MyPoolableObject();
@need4spd
need4spd / MyPoolableObject.java
Created February 13, 2019 14:19
MyPoolableObject
public class MyPoolableObject {
private static int id = 0;
public MyPoolableObject() { id++; }
public int getId() { return id; }
}
@need4spd
need4spd / Test.java
Created February 13, 2019 13:48
Callable and Future sample
import java.util.concurrent.*;
public class FutureAndCallableExample {
public static void main(String[] args) throws InterruptedException, ExecutionException {
System.out.println("Main : " + Thread.currentThread().getName());
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<String> callable = () -> {
System.out.println("Entered Callable");
@need4spd
need4spd / 1.java
Created November 30, 2012 07:17
MultiThreaded Test with Junit
public class Tester implements Runnable {
private Log logger = LogFactory.getLog(Tester.class);
int i = 0;
public Tester(int i ) {
this.i = i;
}
public void run() {