sparksql で emoji/pictogram を含む行を検出する
select text from table where dt='20190911' and text rlike '[\\uD800-\\uDFFF]'
とかでとりあえず良さそう。
select text from table where dt='20190911' and text rlike '[\\uD800-\\uDFFF]'
とかでとりあえず良さそう。
fuse が動かないので ./jetbrains-toolbox-1.15.5796/jetbrains-toolbox --appimage-extract
で解凍。
APPDIR=$PWD/squashfs-root ./squashfs-root/AppRun
で実行可能。
と、思ったが、sudo apt fuse
すれば普通に実行できた。
とりあえずこんな感じで。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()
そもそも剣で切り合うアクションあんま好きじゃない気がしてきた
長年、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 を直接使っても大した差がないことがわかったので、使うのをやめて直接使うことにした。
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.sleuth.sampler.rate
というプロパティを設定すると良い。
https://github.com/spring-cloud/spring-cloud-sleuth/pull/1175
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}`);
});
List::Util::all みたいなものをJSで書くときってどう書くのがいいんだろ
lodash とかにありそうだけど
syohex [8:55 PM]
Array.prototype.everyとは違うのでしたっけ ?
karupanerura [8:56 PM]
それだ。some/everyが今はありますね(名前が思い出せなかった
https://qiita.com/Nossa/items/4a425e57ec4b7eedb7cb
https://twitter.com/typester/status/1089932791150592001
最近はhelmやめてivyつかってますよ! とのこと。僕も変えてみた。
https://www.slideshare.net/tokuhirom/20190126-yapc-tokyo-keynote
keynote の準備に忙しかったりしてあまりトーク聞けなかったけど楽しかったです。
shopt -s globstar
で OK
https://yapcjapan.org/2019tokyo/
キーノートというのをするのが初めてなのでどういう話をしたら良いのかよくわかってない部分もありますが、僕のキャリア・エンジニアリングに関する考え方などを紹介しようかなあと思います。
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-cloud-sleuth を依存にいれたら ERROR レベルでのログの出方がおかしくなった。
このクラスが例外をキャッチしてエラーログに書いて 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
bootRun {
sourceResources sourceSets.main
}
この設定をすると、静的リソースが source directory から読まれるようになり開発が快適になる、とのこと。
以下の様にすれば良いっぽい。
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 に移行させてみた。 理由としては以下。
といったところで、デメリットとしてはとりあえず以下がある。
で、実際に触ってみた感じの感想は以下。
現状では無理して移行する理由はないかな。