Skip to content

Instantly share code, notes, and snippets.

View torao's full-sized avatar
🤒
stacked

Torao Takami torao

🤒
stacked
View GitHub Profile
@torao
torao / gist:1612307
Created January 14, 2012 18:13
BSD License Statement for file header of my Java source.
/* **************************************************************************
* Copyright (C) 2012 BJoRFUAN. All Right Reserved
* **************************************************************************
* This module, contains source code, binary and documentation, is in the
* BSD License, and comes with NO WARRANTY.
*
* takami torao <koiroha@gmail.com>
* http://www.moyo.biz/
*/
@torao
torao / gist:1613789
Created January 15, 2012 01:31
My Design Pattern for Asyncronous I/O
/*
* description code for http://d.hatena.ne.jp/kuromoyo/20120115/1326621574
*/
import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.util.*;
public class AsyncIO1 {
@torao
torao / jvmdump.py
Created February 14, 2012 01:23
Script to dump Java VM stacktrace on all cluster.
#!/usr/bin/python
# -*- encoding: UTF-8 -*-
# Script to dump Java VM stacktrace on all cluster.
# Please configure your unix account to sudo to each user of jvm processes without
# password on each server.
import commands
import re
import time
cluster = [
/* RandomAccessFile をストリームとして扱いたい時はあるけど、こんな書き方でも環境互換性は
* 保証されるんだっけ? org.apache.hadoop.hdfs.server.common.Storage より
*/
public void read(File from) throws IOException {
RandomAccessFile file = new RandomAccessFile(from, "rws");
FileInputStream in = null;
try {
in = new FileInputStream(file.getFD());
file.seek(0);
Properties props = new Properties();
@torao
torao / gist:2167869
Created March 23, 2012 07:06
Simple program to produce "promotion failed" GC
/**
* Simple program to produce "promotion failed" garbage collection on Oracle
* Java VM. For JDK 1.6, please execute with following extended options.
*
* java -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:ParallelGCThreads=8
* -Xmx32m -XX:NewSize=20m -XX:MaxNewSize=20m -server -verbose:gc
* -XX:+PrintGCDetails -XX:+PrintGCDateStamps PromFailed
*/
public class PromFailed {
private static class Watchdog extends Thread {
@torao
torao / gist:3037247
Created July 3, 2012 02:58
StackTrace of TaskTracker in Load Spiking after Jun 30 2012 Leapsecond
2012-07-02 19:30:36
Full thread dump Java HotSpot(TM) 64-Bit Server VM (23.0-b21 mixed mode):
"Attach Listener" daemon prio=10 tid=0x00007fe47488d800 nid=0x54b7 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"taskCleanup" daemon prio=10 tid=0x00007fe4749c5000 nid=0x6190 waiting on condition [0x00007fe465fa9000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000d0370f60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
@torao
torao / gist:3511823
Created August 29, 2012 12:34
Apache License 2.0 ファイルヘッダ
/**
* Copyright 2012 BJöRFUAN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@torao
torao / gist:5898602
Last active December 19, 2015 04:39
How to retrieve raw JSON status from Twitter Sample Stream API using twitter4j. / twitter4j を使用して Twitter Sample API から生の JSON を取得する方法。
import twitter4j._
import twitter4j.conf._
import twitter4j.json._
object Stream extends RawStreamListener {
def main(args:String):Unit = {
val conf = new ConfigurationBuilder()
.setDebugEnabled(true)
.setOAuthConsumerKey("xxxx")
.setOAuthConsumerSecret("xxxx")
@torao
torao / using.scala
Created July 15, 2013 14:24
Java のリソース構文や C# の using 節に似た Scala 版の何らかのもの。型パラメータ U は U >: java.io.Closeable の方が良いのかもしれないけど java.sql.Connection などを考えると structual subtyping の方が汎用的なのかなぁと。
// ex.,
// using(new FileInputStream("foo.txt")){ in => ... }
// using(DriverManager.getConnection("jdbc:db://localhost/foo")){ con => ... }
def using[T,U <% { def close():Unit }](c:U)(f:(U)=>T):T = try { f(c) } finally { c.close() }
@torao
torao / HowToUseSelfSignedCert.scala
Last active January 30, 2018 08:41
Scala と Java で自己署名証明書を使用したクライアント/サーバ認証 (SSL) のサンプルコード / A sample code to authenticate with self-signed certificate on Scala and Java. http://koiroha.blogspot.jp/2013/11/how-to-use-sslsocket-with-selfsigned-certificates-on-scala-or-java.html
/*
* Copyright (c) 2013 koiroha.org.
* All sources and related resources are available under Apache License 2.0.
* http://www.apache.org/licenses/LICENSE-2.0.html
*/
import java.io._
import java.security.KeyStore
import java.util.Date
import javax.net.ssl._
import scala.concurrent.duration.Duration