Skip to content

Instantly share code, notes, and snippets.

@relax-more
relax-more / memo.sh
Created June 4, 2013 08:36
[http] 大きなファイルの download に http Partial GET をご利用ください
# --header "Range: byte=a-b" can partial download.
$ curl --header "Range: bytes=0-200000" http://anyhost.com/anyfile.zip -o part1
$ curl --header "Range: bytes=200001-400000" http://anyhost.com/anyfile.zip -o part2
$ curl --header "Range: bytes=400001-600000" http://anyhost.com/anyfile.zip -o part3
$ curl --header "Range: bytes=600001-800000" http://anyhost.com/anyfile.zip -o part4
$ curl --header "Range: bytes=800001-1000000" http://anyhost.com/anyfile.zip -o part5
$ cat part1 part2 part3 part4 part5 > anyfile.zip
$ wc -c anyfile.zip
835428 anyfile.zip
@relax-more
relax-more / TestClass.java
Last active October 6, 2017 09:12
[java] generate random MD5 string (very naive...)
public class TestClass{
private String generateToken(){
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
// coding error.
LOGGER.error("codeing error. ", e);
throw new RuntimeException(e);
}
@relax-more
relax-more / gist:5764676
Created June 12, 2013 12:03
[network] sticky で session 維持しながらバランシング
セッション維持
 負荷分散環境の構築により、サーバ負荷の軽減やユーザーへのスループット向上を実現できます。参照系のサイトであれば、同一クライアントからの要求をセッションごとにどのサーバに割り振っても特に問題にはなりません(もちろん、各ノード内のコンテンツの同期が取れていることが前提です)。
 しかし、ショッピングサイトで買い物中に同一クライアントからのセッションが異なるサーバに分散されたのでは、せっかく買おうと思ってショッピングカートに詰め込んだ商品が消失してしまうことにもなりかねません。
 そこで、「セッションの維持」が必要となります。同一クライアントからの要求は同一サーバに固定的に割り振り、同一サーバを使ってセッションを維持するということです。
 セッション維持の方法には幾つかありますが、昨今のブラウザ環境の多様化に伴い、新しい維持方法(Sticky)も必要となってきています。ここではそれらも含めて説明します。
下記よりコピペ
http://www.atmarkit.co.jp/ait/articles/0106/09/news002.html
@relax-more
relax-more / nginx.conf
Created June 13, 2013 02:48
[nginx] http と https を両方利用するための設定
upstream gappori_shop {
server gappori_shop.com:20080;
}
server {
listen 80;
server_name shop.nureteni.awa.co.jp;
location / {
proxy_pass http://gappori_shop;
@relax-more
relax-more / gist:5779915
Created June 14, 2013 06:40
[Hive] 実行結果をそのままファイルに出力する
$ hive -S -e ‘select * from tbl_a limit 100′ > hive_result.txt
@relax-more
relax-more / gist:5811583
Created June 19, 2013 03:56
[java] generics に関するメモ
■generics で T.class したかった話
http://d.hatena.ne.jp/language_and_engineering/20120502/p1
■generics に関して多くの情報があるブログ
http://d.hatena.ne.jp/Nagise/
@relax-more
relax-more / gist:5812779
Created June 19, 2013 08:54
[MongoDB] set TTL in collection
2.2.x からの新機能で、CollectionのDataにTTLを設定できる
詳しくはこちら。
http://docs.mongodb.org/manual/tutorial/expire-data/
実装に関してはこちら。 
http://www.codeproject.com/Tips/467689/MongoDB-Time-To-Live-TTL-Collections
(java のensureIndex からは適用できなかったのでshell から実施。MongoDB Version:2.4, MongoDB JavaDriver:2.11.1 )
■参照・余談
@relax-more
relax-more / LocaleChangeInterceptor.java
Last active December 18, 2015 16:39
[java] spring framework, locale の判定と、それに応じた表示文言の切り替えに関してメモ
public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// any logic...
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
@relax-more
relax-more / ref.txt
Last active December 19, 2015 05:49
[java][spring] SpringMVC の redirect を利用した際にHttpsを引き続き利用するための設定
Spring MVC “redirect:” prefix always redirects to http — how do I make it stay on https?
http://stackoverflow.com/questions/3401113/spring-mvc-redirect-prefix-always-redirects-to-http-how-do-i-make-it-stay/3401157#3401157
@relax-more
relax-more / gist:5915799
Created July 3, 2013 06:12
[java][html] httpServlet request のURL 関連パラメータの取得方法メモ
HttpServletRequest から取得できるPath関連の情報
http://cdn-ak.f.st-hatena.com/images/fotolife/u/uriyuri/20080718/20080718103706.jpg
元:
http://d.hatena.ne.jp/uriyuri/20080718/1216345412