Skip to content

Instantly share code, notes, and snippets.

@tksmaru
tksmaru / authentication.js
Created November 11, 2015 21:10
javascriptにおける継承の実装サンプル
module.exports = Authentication;
// @Constructor
function Authentication(name) {
this._name = name;
};
Authentication.prototype._login = function(loginId, password) {
throw new Error("not implemented");
@tksmaru
tksmaru / MainActivity.java
Created August 6, 2015 22:40
Android API levelを意識したNotificationの実装例
package com.example.maruyama.helloandroid5;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
package org.tksmaru.playgound;
import java.lang.reflect.Constructor;
public class ActiveClassWithReflection {
private enum ErrorType {
LESS_MONEY("less.money", UserException.class),
NO_STOCK("no.stock", ShopException.class),
@tksmaru
tksmaru / ReflectionTest.java
Last active December 16, 2015 07:19
リフレクションのおかげで寡黙な○野さんもお喋り好きになりました。
import java.lang.reflect.Field;
public class ReflectionTest {
public static void main(String[] args) throws Exception {
Mizuno mizuno = new Mizuno();
System.out.println("リフレクション前 : " + mizuno.talk()); // …
Class<? extends Mizuno> clazz = mizuno.getClass();
@tksmaru
tksmaru / Boxing.java
Created April 16, 2013 17:03
オートボクシングは楽でいいですね
// JDK 1.4 style
List oldList = new ArrayList();
oldList.add(Integer.valueOf(1));
int oldNumber = ((Integer) oldList.get(0)).intValue();
// JDK 1.5 over
List<Integer> newList = new ArrayList<Integer>();
newList.add(1);
int modernNumber = newList.get(0);
@tksmaru
tksmaru / countup.groovy
Last active December 16, 2015 07:18
0.1を10回足しあわせても1にはならないよ
double count = 0;
10.times {
count += 0.1
}
print count
@tksmaru
tksmaru / InterfaceTest.java
Created April 16, 2013 16:36
適切なインターフェース型が存在しない例のその2
public class InterfaceTest {
public static void main(String[] args) {
// 基底クラスで型を宣言
CoreSysMember member = new Ohta();
//CoreSysMember member = new ItashikiPro();
System.out.println(member.getName());
}
/**
@tksmaru
tksmaru / StringUtilsTest.groovy
Last active December 15, 2015 21:19
StringUtilsにまんまと騙された件
@Grab(group='commons-lang', module='commons-lang', version='2.6')
import org.apache.commons.lang.StringUtils;
assert ! StringUtils.isAlpha("2"); // false
assert StringUtils.isAlpha("a"); // true
assert ! StringUtils.isAlpha(""); // true…だと…?
@tksmaru
tksmaru / InterfaceTest.java
Created April 5, 2013 00:37
引数が継承関係にあるオーバーロードメソッドの挙動確認
import java.util.*;
/**
* 引数が継承関係にあるオーバーロードメソッドの実験
*/
public class InterfaceTest {
/** Collection を要求する */
public static <T> void doSomething(Collection<T> collection) {
System.out.println("1");
@tksmaru
tksmaru / CollectionUtils.java
Created April 3, 2013 13:59
Listを指定サイズ毎に分割するutility
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CollectionUtils {
/**
* Listを指定したサイズ分割します
*
* @param origin 分割元のList