Skip to content

Instantly share code, notes, and snippets.

View mahata's full-sized avatar
💭
On parenting...

Yasunori MAHATA mahata

💭
On parenting...
View GitHub Profile
@mahata
mahata / Main.java
Last active January 1, 2019 14:35
How remove() works in loops
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
for (String str : list) {
if ("B".equals(str)) {
@mahata
mahata / Main.java
Created December 30, 2018 14:46
StringBuffer takes 16 bytes as buffer
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
StringBuilder sb = new StringBuilder("abcde");
System.out.println(sb.capacity()); // 21: StringBuilder takes 16 bytes as buffer by default
}
}
# -*- coding:utf-8 -*-
import json, config, time, MeCab
from requests_oauthlib import OAuth1Session
from jinja2 import Template
CK = config.CONSUMER_KEY
CS = config.CONSUMER_SECRET
AT = config.ACCESS_TOKEN
ATS = config.ACCESS_TOKEN_SECRET
twitter = OAuth1Session(CK, CS, AT, ATS)
@mahata
mahata / original.md
Last active September 26, 2018 14:17
abstract class "ClassA" as ClassA {
{abstract}methodA();
}

class "SubClassA1" as SubClassA1 {
methodA();
}

class "SubClassA2" as SubClassA2 {
fun isUniqueChars(str: String): Boolean {
if (str.length > 256) return false
var checker: Int = 0
for (idx in 0..(str.length-1)) {
val value: Int = str[idx] - 'a'
if ((checker and (1 shl value)) > 0) {
return false
}
checker = checker or (1 shl value)
rules <<<
  # Compute a rate per task and per ‘code’ label
  {var=task:http_responses:rate10m,job=webserver} =
    rate by code({var=http_responses,job=webserver}[10m]);

  # Compute a cluster level response rate per ‘code’ label
  {var=dc:http_responses:rate10m,job=webserver} =
    sum without instance({var=task:http_responses:rate10m,job=webserver});
import java.util.Calendar
import TimeInterval.*
// 前提となるクラス群
enum class TimeInterval { DAY, WEEK, YEAR }
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int)
// RepeatedTimeInterval は TimeInterval と Int の値をプロパティとして持つ
// TimeInterval (すなわちDAY or WEEK or YEAR) が何回分 (Int) か、というデータ構造
class RepeatedTimeInterval(val timeInterval: TimeInterval, val number: Int)
data class MyValue(val value: Int) {
operator fun plus(other: MyValue): MyValue {
return MyValue(value + other.value)
}
}
public fun main(args: Array<String>) {
val a = MyValue(1)
val b = MyValue(2)
println(a + b) // MyValue(value=3)
val arrayList = arrayListOf(1, 5, 2)
Collections.sort(arrayList, { x, y -> y - x })
val arrayList = arrayListOf(1, 5, 2)
Collections.sort(arrayList, object : Comparator<Int> {
override fun compare(o1: Int, o2: Int) = o2 - o1
})