Skip to content

Instantly share code, notes, and snippets.

View kazuhito-m's full-sized avatar

Kazuhito Miura kazuhito-m

View GitHub Profile
@kazuhito-m
kazuhito-m / ClassesListUper.java
Created February 19, 2020 12:56
パッケージからクラスの一覧を取得するやつ
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static java.util.stream.Collectors.toList;
@kazuhito-m
kazuhito-m / SpringELTest.java
Last active February 19, 2020 09:09
SpringELのサンプル
import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import java.util.HashMap;
import java.util.Map;
@kazuhito-m
kazuhito-m / top_number8_sep_underbar_rename.sh
Last active December 25, 2018 02:49
ファイル名が「先頭8文字数値」の場合にアンダーバーを付与するbashスクリプト
#!/bin/bash
# 「ファイル名の先頭が8ケタの数値」の名前のファイルに
# 数値とその次の文字の間にアンダーバーを挟んだ名前にリネームするスクリプト。
for i in $(ls | grep '^[0-9]\{8\}') ; do
newname=`echo $i | sed -e 's/^\([0-9]\{8\}\)/\1_/g'`
mv ${i} ${newname}
done
@kazuhito-m
kazuhito-m / folderLimitChecker.ps1
Last active January 25, 2018 18:19
PowerShellで書いた「指定フォルダ直下の容量チェック」
# フォルダ容量チェッカー。
#
# フォルダの上限と容量を指定すると、
# 直下のフォルダがその容量を超えていた場合に、
# 警告ファイル(warning.log)を出力する。
#
# ex. folderLimitChecker.ps1 C:work 1000000
#
Param( $targetFolder, $maxSize )
def target = this.args[0]
/**
* ASCII(&ある種決まった記号)のみで構成されているかを真偽値で返す。
*/
def isAsciiOnly(text) {
def valids = ['-', '_']
for (c in text.split('')) {
if (((int) c) > 127 && !valids.contains(c)) return false
}
@kazuhito-m
kazuhito-m / SurrogatePairsTest.java
Created November 2, 2017 04:35
サロゲートペアに関するいろいろ確認
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class SurrogatePairsTest {
@Test
public void 文字コード指定でサロゲートペア文字列を作成する() {
char[] surrogatePairChars = new char[]{0xd867, 0xde3d}; // サカナ偏に花
@kazuhito-m
kazuhito-m / SampleNew.groovy
Last active April 15, 2017 10:37
Microsoft Translator APIの新と旧
import javax.net.ssl.HttpsURLConnection
import java.net.URLEncoder
def getToken(key) {
def authenticationUrl = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"
def conn = new URL(authenticationUrl).openConnection()
conn.setRequestMethod("POST")
conn.setDoOutput(true)
conn.setRequestProperty("Ocp-Apim-Subscription-Key", key)
conn.getOutputStream().write(0)
@kazuhito-m
kazuhito-m / KazuhitoM.java
Created August 23, 2015 09:44
「どんな大きさが好きか、コードで示せ」って言われたので…。
public class KazuhitoM {
public static void main(String[] args) {
KazuhitoM self = new KazuhitoM();
System.out.println(String.format("%s が好きなのは %s 感じのです。"
, self.getClass().getCanonicalName()
, self.getLikeSize().getCaption()));
}
/**
@kazuhito-m
kazuhito-m / BooleanPrimitiveAndBoxingTest.java
Created March 19, 2015 10:08
JavaでBooleanのvalueOf()とnewと定数との比較を行うサンプル。
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
/**
* BooleanのvalueOf()とnewと定数との比較を行うテスト。
* @author kauzhito_m
*/
public class BooleanPrimitiveAndBoxingTest {
@kazuhito-m
kazuhito-m / Janken.groovy
Last active August 29, 2015 14:12
じゃんけんプログラム(Groovy版)
/*
* Special Thanks!
* 監修/コードレビュアー: @bufferings さん、 @megascus さん。 (ミウラはほぼアイディアだけ…トホホ)
*/
import org.junit.Test
/** じゃんけんの"手"を表わす定数群。 */
enum Sign {
pa, ty, gu;