Skip to content

Instantly share code, notes, and snippets.

View HeartSaVioR's full-sized avatar
๐Ÿ 
Working from home

Jungtaek Lim HeartSaVioR

๐Ÿ 
Working from home
View GitHub Profile
@HeartSaVioR
HeartSaVioR / BlpopTest.java
Last active August 29, 2015 14:00
Blpop with forcing waiting thread to interrupt
public class ListCommandsTest extends JedisCommandTestBase {
public void blpopWithForceKill() throws InterruptedException {
Thread th = new Thread(new Runnable() {
@Override
public void run() {
jedis.blpop(100, "foo");
}
});
th.start();
package net.heartsavior.dev;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
public class JedisConnectionSuddenlyBrokenTest {
public static void main(String[] args) throws InterruptedException {
Jedis jedis = new Jedis("127.0.0.1", 6379);
@HeartSaVioR
HeartSaVioR / JedisPubSubTest.java
Last active August 29, 2015 13:56
JedisPubSubTest with Redis Cluster (include node down)
package net.heartsavior.dev;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@HeartSaVioR
HeartSaVioR / pipelined_transaction_workaround.java
Last active August 29, 2015 13:56
Jedis pipelined transaction sync() errors workaround
Jedis j = new Jedis(HOSTNAME, PORT);
j.set("foo", "314");
Pipeline p = j.pipelined();
p.multi();
Response<String> r = p.get("foo");
Response<String> multiResp = p.exec();
p.sync();
multiResp.get(); // to achieve r.get()
System.out.println(r.get());
var randomized_words = [ 'anguilliform', 'concenter', 'ciao', 'kyloe', 'psychologize',
'paddywhack', 'misshaping', 'fleshless', 'invigilated', 'jointless',
'circumambulation', 'adown', 'avaunt', 'cachinnate', 'protistan', 'alkanet',
'extravagate', 'ochone', 'ta', 'meristematic', 'keck', 'unremunerative',
'frapping', 'anent', 'concertize', 'bechance', 'nontaxable', 'bhindi', 'olearia',
'transduce', 'humph', 'malamute', 'barhopping', 'triangulate', 'premandibular',
'stodge', 'crankle', 'souk', 'cose', 'ligate', 'brava', 'syne', 'chez', 'biomass',
'blithesome', 'trinomially', 'appetence', 'kindheartedly', 'venge', 'annulation',
'trophallactic', 'semiautomatically', 'particulate', 'valleculate', 'dewan', 'exudation',
'lavolta', 'coze', 'goodby', 'vitrified', 'outpace', 'putaminous', 'orthopteran',
import urllib
from time import sleep
url_template = "https://m.mypeople.daum.net/img/i1.daumcdn.net/air21.sticker/pc/still_img/sticker_%03d.png"
start_range=0
end_range=1500 # 2013/08/14 last id : 1457
sleep_for_crawl_success = 1
sleep_for_crawl_fail = 2
for sticker_id in range(start_range, end_range+1):
package storm.starter;
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseRichBolt;
@HeartSaVioR
HeartSaVioR / JedisPoolFactoryBean.java
Created June 29, 2013 14:54
JedisPool ์˜ ์ƒ์„ฑ์ž๋Š” host, port ์ž…๋ ฅ๊นŒ์ง€๋Š” Config ๊ฐ์ฒด๋ฅผ ๋ฐ›์ง€ ์•Š๋‹ค๊ฐ€, timeout, password, db number ๋“ฑ์„ ์ถ”๊ฐ€๋กœ ์ž…๋ ฅํ•  ๋•Œ์—๋Š” Config ๊ฐ์ฒด๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ž…๋ ฅ๋ฐ›์Šต๋‹ˆ๋‹ค. Spring ์„ ํ†ตํ•ด JedisPool bean ์„ ์ƒ์„ฑํ•  ๋•Œ, ์ด๋Ÿฐ ์ƒ์„ฑ์ž ์ „๋‹ฌ์ธ์ž ์ฐจ์ด๋Š” bean ์ƒ์„ฑ์— ๋ถˆํŽธํ•˜๊ฒŒ ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด, FactoryBean ์„ ์ •์˜ํ•˜๊ณ  bean ์— ์„ค์ •๋˜๋Š” ์ •๋ณด์— ๋งž๊ฒŒ JedisPool ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๋„๋ก ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
package net.heartsavior.spring.jedis;
import org.apache.commons.pool.impl.GenericObjectPool.Config;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Protocol;
public class JedisPoolFactoryBean extends AbstractFactoryBean<JedisPool> {
<!-- ๋ฆด๋ฆฌ์ฆˆ์‹œ ์˜์กด๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํฌํ•จ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
@HeartSaVioR
HeartSaVioR / GsonObjectMapper.java
Created June 13, 2013 15:20
๊ธฐ๋ณธ ์„ค์ •์˜ Gson ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด Model -> JSON ์„ ๋ณ€ํ™˜ํ•˜๊ฒŒ ๋˜๋ฉด Model ๋‚ด Date ํ•„๋“œ์˜ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๊ฐ€ ์‚ฌ๋ผ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค (๊ฒฐ๊ณผ์ ์œผ๋กœ JSON <-> Model ๊ฐ„์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š๊ฒŒ ๋ฉ๋‹ˆ๋‹ค) ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด, Model -> JSON ๋ณ€ํ™˜ ์‹œ Date ํ•„๋“œ๋ฅผ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๊นŒ์ง€ ๋ฝ‘์•„๋‚ด๋„๋ก ํฌ๋งท์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค ์œ„์˜ ๋‚ด์šฉ์€ https://gist.github.com/leviwilson/2495636 ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class GsonObjectMapper {
public static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
private Gson gson;
public GsonObjectMapper() {