Skip to content

Instantly share code, notes, and snippets.

@takumakei
takumakei / RutimeInit.java
Created April 8, 2011 06:09
my favorite code for Android projects.
/* RuntimeInit.java
* My favorite initialization code for Android applications.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / HexDump.java
Created April 8, 2011 08:57
yet another HexDump
/* HexDump.java
* Yet another HexDump. It prints bytes in human readable text.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / IOUtil.java
Created April 8, 2011 13:07
The class has some static methods to use streams easily.
/* IOUtil.java
* The class has some static methods to use streams easily.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / JSONEntity.java
Created April 11, 2011 04:53
An utility class to POST json(optionally gzipped) with Apache HttpClient.
/* JSONEntity.java
* An utility class to POST json(optionally gzipped) with Apache HttpClient.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / EuclideanAlgorithm.java
Created April 12, 2011 05:25
An implementation of the method for computing the greatest common divisor.
/* EuclideanAlgorithm.java
* An implementation of the method for computing the greatest common divisor.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / hex_dump.rb
Created May 9, 2011 06:10
print hex dump of a string
# hex_dump.rb
# print hex dump of a string
module HexDump
module_function
def hex_dump(str)
cs = str.unpack 'C*'
puts "[#{cs.size} bytes]"
addr = 0
loop do
cs16 = cs.shift 16
@takumakei
takumakei / MarkerFilter.java
Created May 24, 2011 15:50
Logback NON-turbo filter checks whether the marker in the event matches the marker
/* MarkerFilter.java
* Logback NON-turbo filter checks whether the marker in the event matches the marker.
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
@takumakei
takumakei / qrcode.js
Created October 6, 2011 09:39
qrcode.js for the bookmarklet
// bookmarklet: qrcode
//
// javascript:void((function(d){var s=BOOKMARKLETSCRIPT=d.createElement('script');s.type='text/javascript';s.src='https://raw.github.com/gist/1266971/b5e0748c51dd0ffdf4a1abb00d14409a8220b7c2/qrcode.js';d.getElementsByTagName('head')[0].appendChild(s);})(document));
//
try {
(function(d){
var body = d.getElementsByTagName('body')[0];
var add = function(args) {
var target = args.target || body;
var elem = d.createElement(args.tag || 'div');
@takumakei
takumakei / is_array.js
Created October 19, 2011 14:57
is_array
// is_array():bool
// "JavaScript: The Good Parts by Douglas Crockford. Copyright 2008 Yahoo! Inc., 978-0-596-51774-8."
function is_array(value) {
return value &&
typeof value === 'object' &&
typeof value.length === 'number' &&
typeof value.splice === 'function' &&
!(value.propertyIsEnumerable('length'));
};
@takumakei
takumakei / TProcessors.java
Created November 25, 2011 07:25
Create an instance of org.apache.thrift.TProcessor bound to the classes at run time
/* TProcessors.java
* Create an instance of org.apache.thrift.TProcessor bound to the classes at run time.
* TProcessor processor = TProcessors.newInstance(Class.forName(className), Class.forName(serviceName));
*
* Copyright (C) 2011 TAKUMAKei
*
* 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
*