Blog

sparksql で emoji/pictogram を含む行を検出する

select text from table where dt='20190911' and text rlike '[\\uD800-\\uDFFF]'

とかでとりあえず良さそう。

filebeat で jvm unified log を収集する話

jetbrains toolbox for linux を chromebook で動かす

fuse が動かないので ./jetbrains-toolbox-1.15.5796/jetbrains-toolbox --appimage-extract で解凍。 APPDIR=$PWD/squashfs-root ./squashfs-root/AppRun で実行可能。

と、思ったが、sudo apt fuse すれば普通に実行できた。

Unable to publish SessionDestroyedEvent for session foobar

https://github.com/spring-projects/spring-session/blob/033d6eecaeabe1adaa4deedc9a3019cf9260fcbc/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java#L536

scala で guava のバージョンを確認する

とりあえずこんな感じで。try-with-resources でやりたかったが、あんま短くかけなそうだった。

%spark
import java.util.Properties
import com.google.common.io.Resources

val resourceName = "META-INF/maven/com.google.guava/guava/pom.properties";
val properties = new Properties();
val inputStream = Resources.getResource(resourceName).openStream();
properties.load(inputStream);
println(properties.getProperty("version"))
inputStream.close()

witcher 3 途中でやめた

そもそも剣で切り合うアクションあんま好きじゃない気がしてきた

pageres から capture-website にしようと思ったが puppeteer にした

長年、pageres を利用して web page から画像を生成していた。 pageres の後継として capture-website があることを知った。

https://github.com/sindresorhus/capture-website

The biggest difference is that Pageres supports capturing multiple screenshots in a single call and it automatically generates the filenames and writes the files. Also, when projects are popular and mature, like Pageres, it becomes harder to make drastic changes. There are many things I would change in Pageres today, but I don't want to risk making lots of breaking changes for such a large userbase before I know whether it will work out or not. So this package is a rethink of how I would have made Pageres had I started it today. I plan to bring some things back to Pageres over time.

しかし、いろいろ試した結果、puppeteer を直接使っても大した差がないことがわかったので、使うのをやめて直接使うことにした。

https://github.com/GoogleChrome/puppeteer

Excel で特定の行または列を固定する方法

https://www.techonthenet.com/excel/questions/freeze2_2011.php

この辺。

zipkin の RateLimitingSampler が便利(特に低トラフィックの場合)

zipkin で tracing log を取得する場合、一定の割合でログをサンプリングしてストレージに保存していた(たとえば 0.1% だけストアするなど)

この方法では、低トラフィックな環境ではログが十分取りづらいし、トラフィックが急に増えた場合を考えると、サンプリグレートを上げるのも怖いという問題があった。

しかし、zipkin brave の 5.6.0 以後では RateLimitingSampler という実装が導入されている。これにより、1秒間にどれだけ送るかという上限設定ができるようになり、トラフィック量に応じて sampling rate を変更する手間が省けるようになっている。

https://github.com/apache/incubator-zipkin-brave/pull/819 https://github.com/apache/incubator-zipkin-brave/blob/master/brave/src/main/java/brave/sampler/RateLimitingSampler.java

Spring Cloud Sleuth の場合

Spring cloud sleuth でもこの機能にすでに対応されていて、spring.sleuth.sampler.rate というプロパティを設定すると良い。

https://github.com/spring-cloud/spring-cloud-sleuth/pull/1175

line-bot-sdk-nodejs を typescript で使う

	npm install --save express
	npm install --save typescript
        npm install --save @line/bot-sdk
	npm install --save @types/express
	npm install --save @types/node

	npm install --save-dev ts-node
	npm install --save-dev ts-node-dev

	npx tsc --init

	mkdir src
	touch src/index.ts

	npx ts-node src/index.ts

とかでセットアップして

npx ts-node-dev --respawn src/index.ts

で起動。

コードはこんな感じ(typescript 慣れてないから怪しい)。

import line = require('@line/bot-sdk');
import express = require('express');


const config: line.Config =  {
  channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!,
  channelSecret: process.env.LINE_CHANNEL_SECRET!,
};

// create LINE SDK client
const client = new line.Client(<line.ClientConfig>config);

// create Express app
// about Express itself: https://expressjs.com/
const app = express();

// register a webhook handler with middleware
// about the middleware, please refer to doc
app.post('/callback', line.middleware(<line.MiddlewareConfig>config), (req, res) => {
  Promise
    .all(req.body.events.map(handleEvent))
    .then((result) => res.json(result))
    .catch((err) => {
      console.error(err);
      res.status(500).end();
    });
});


// event handler
function handleEvent(event: line.WebhookEvent) {
  if (event.type !== 'message' || event.message.type !== 'text') {
    // ignore non-text-message event
    return Promise.resolve(null);
  }

  console.log(`Received message: ${event.message.text}`);

  // create a echoing text message
  const echo: line.TextMessage = { type: 'text', text: event.message.text };

  // use reply API
  return client.replyMessage(event.replyToken, echo);
}

// listen on port
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`listening on ${port}`);
});

[js] List::Util::all みたいなのを js で

 List::Util::all みたいなものをJSで書くときってどう書くのがいいんだろ
lodash とかにありそうだけど
syohex [8:55 PM]
 Array.prototype.everyとは違うのでしたっけ ?
karupanerura [8:56 PM]
 それだ。some/everyが今はありますね(名前が思い出せなかった
https://qiita.com/Nossa/items/4a425e57ec4b7eedb7cb

ivy が最近は良いらしい

https://twitter.com/typester/status/1089932791150592001

最近はhelmやめてivyつかってますよ! とのこと。僕も変えてみた。

YAPC::Tokyo 2019 で keynote してきた

https://www.slideshare.net/tokuhirom/20190126-yapc-tokyo-keynote

keynote の準備に忙しかったりしてあまりトーク聞けなかったけど楽しかったです。

bash で **/* とかしたい

shopt -s globstar で OK

YAPC::Tokyo 2019 で keynote します

https://yapcjapan.org/2019tokyo/

キーノートというのをするのが初めてなのでどういう話をしたら良いのかよくわかってない部分もありますが、僕のキャリア・エンジニアリングに関する考え方などを紹介しようかなあと思います。

spring の 4.3.15, 5.0.5 以後で mockmvc の json path のマッチングで matcher 使わなくてもよくなってる

mockmvc で jsonpath のマッチングを利用する場合、以下のようにする必要があった。

.andExpect(jsonPath("$.id", is(5963)))

これはこれでいいのだが、他の API と一貫性がなく、補完も効きづらく、hamcrest API ではなく assertj をメインで使ってる身としては辛かった。

また long の扱いが渋くて、辛かった。。 https://stackoverflow.com/questions/37996419/how-to-force-andexpectjsonpath-to-return-long-long-instead-int-for-int-num

SPR-16587 MockMvcResultMatchers.jsonPath(String).value() should have a matching method to declare the expected type で、問題が解決されて以下のような書き方ができるようになっている。

.andExpect(jsonPath("$.id").value(5963)))

MockMvc でテストを書いているときに部分一致をしたいケースは殆どないと思われるので、このスタイルで書くのが良いと私は思います。

Spring 4.3.15, 5.0.5 以後で使えるので、このスタイルで書いたほうが良い。

古いコードをコピペし続けているとこのような古い書き方に引きづられがちなので気をつけていきたい。

【追記】 null であることを保証したいときは hamcrest matcher でやらないと駄目。

spring boot で ExceptionLoggingFilter が ERROR level でログ出まくってうざいってとき

spring-cloud-sleuth を依存にいれたら ERROR レベルでのログの出方がおかしくなった。

https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/ExceptionLoggingFilter.java

このクラスが例外をキャッチしてエラーログに書いて rethrow するという謎の挙動をしている。。

なんのためにいったいこのクラスが設定されているのか謎。だが。。

https://cloud.spring.io/spring-cloud-sleuth/multi/multi__integrations.html#_http_filter

この spring.sleuth.web.exception-throwing-filter-enabled プロパティを false に設定することですべてが解決する。


It's fixed by this PR. https://github.com/spring-cloud/spring-cloud-sleuth/pull/1633

spring boot で静的リソースの書き換えを即時反映させたいよってとき

bootRun {
    sourceResources sourceSets.main
}

https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#running-your-application-reloading-resources

この設定をすると、静的リソースが source directory から読まれるようになり開発が快適になる、とのこと。

webflux で x-forwarded-for とかをケアする

以下の様にすれば良いっぽい。

https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-forwarded-headers

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.reactive.config.WebFluxConfigurer
import org.springframework.web.server.adapter.ForwardedHeaderTransformer


@Configuration
class WebConfiguration : WebFluxConfigurer {
    @Bean
    fun forwardedHeaderTransformer(): ForwardedHeaderTransformer {
        return ForwardedHeaderTransformer()
    }
}

あるプロジェクトを Gradle kotlin DSL に移行した

お仕事プロジェクトの一つを gradle kotlin dsl に移行させてみた。 理由としては以下。

といったところで、デメリットとしてはとりあえず以下がある。

で、実際に触ってみた感じの感想は以下。

現状では無理して移行する理由はないかな。