Skip to content

Instantly share code, notes, and snippets.

View komiya-atsushi's full-sized avatar
🏠
Working from home

KOMIYA Atsushi komiya-atsushi

🏠
Working from home
View GitHub Profile
@komiya-atsushi
komiya-atsushi / DateIterator.java
Created August 15, 2012 05:39
Date オブジェクトの任意のフィールドをインクリメントして、for-each ループで繰り返し処理できるようにするクラス。
package biz.k11i.util;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Date オブジェクトの任意のフィールドをインクリメントしながら繰り返す Iterator の実装です。
* <p>
@komiya-atsushi
komiya-atsushi / AdHocTx.java
Created August 20, 2012 05:16
Play framework 向けの、トランザクションを一時的に切り替える処理をお手伝いする機能。
package helpers;
import play.db.jpa.JPA;
import play.db.jpa.JPAPlugin;
/**
* トランザクションを一時的に切り替える機能を提供します。
* <p>
* トランザクションの切り替え・切り戻しは内部で自動的に行われます。
* </p>
@komiya-atsushi
komiya-atsushi / count_sample_tweets.rb
Created August 30, 2012 09:57
statuses/sample の streaming API から流れるツイートの流量を測定する Ruby スクリプト
require 'open3'
API_URL = 'https://stream.twitter.com/1/statuses/sample.json'
USER = 'Twitter_account'
PW = 'password'
INTERVAL_SECONDS = 10
stdin, stdout, stderr = *Open3.popen3("curl #{API_URL} -u#{USER}:#{PW}")
line_count = 0
@komiya-atsushi
komiya-atsushi / gem_cf.sh
Created September 7, 2012 02:47
production.cf.rubygems.org から .gem ファイルをダウンロードする gem コマンドのラッパー (シェルスクリプト)
#!/bin/bash
ORIGINAL_SOURCE=http://rubygems.org/
MIRROR_SOURCE=http://production.cf.rubygems.org/
gem sources -r $ORIGINAL_SOURCE
gem sources -a $MIRROR_SOURCE
gem $*
@komiya-atsushi
komiya-atsushi / DartsMap.java
Created September 22, 2012 09:43
Double Array Trie の Java 実装を Map インタフェースでラップしたもの。
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@komiya-atsushi
komiya-atsushi / HttpResponseHelper.java
Created September 26, 2012 14:16
Twitter4J 2.2.6 を使って Twitter v1.1 API の search/tweets を叩くサンプルコード
package twitter4j.internal.http;
public class HttpResponseHelper {
public static HttpClientConfiguration getHttpClientConfiguration(
HttpResponse res) {
return res.CONF;
}
}
@komiya-atsushi
komiya-atsushi / snappy_unittest.cc
Created October 1, 2012 05:36
LZ4 のベンチマーク機能を追加した snappy_unittest.cc
// Copyright 2005 and onwards Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
@komiya-atsushi
komiya-atsushi / GetSecondsUntilResetDemo.java
Created November 8, 2012 17:06
RateLimitStatus#getSecondsUntilReset() returns a negative value. ( #twitter4j 3.0.0 )
import twitter4j.RateLimitStatus;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
public class GetSecondsUntilResetDemo {
public static void main(String[] args) throws TwitterException {
Twitter twitter = TwitterFactory.getSingleton();
System.out
@komiya-atsushi
komiya-atsushi / GetResetTimeInSecondsDemo.java
Created November 8, 2012 17:46
RateLimitStatus#getResetTimeInSeconds() returns unnecessarily divided value. ( #twitter4j 3.0.0)
import twitter4j.RateLimitStatus;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
public class GetResetTimeInSecondsDemo {
public static void main(String[] args) throws TwitterException {
Twitter twitter = TwitterFactory.getSingleton();
System.out.println("RateLimitStatus#getResetTimeInSeconds() returns unnecessarily divided value.\n");
@komiya-atsushi
komiya-atsushi / 1.stack_trace.txt
Created November 14, 2012 12:57
URLEntityJSONImpl.init() throws JSONException
JSONObject["display_url"] not found.
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=531a610a or
http://www.google.co.jp/search?q=02749ab7
TwitterException{exceptionCode=[531a610a-02749ab7 592f0a99-37b91020], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.0-SNAPSHOT(build: 92708a174b7c103d12f911d331e7e9c23596ecad)}
at twitter4j.internal.json.URLEntityJSONImpl.init(URLEntityJSONImpl.java:70)
at twitter4j.internal.json.URLEntityJSONImpl.<init>(URLEntityJSONImpl.java:43)
at twitter4j.internal.json.StatusJSONImpl.init(StatusJSONImpl.java:164)
at twitter4j.internal.json.StatusJSONImpl.<init>(StatusJSONImpl.java:85)
at twitter4j.internal.json.z_T4JInternalJSONImplFactory.createStatus(z_T4JInternalJSONImplFactory.java:44)