Skip to content

Instantly share code, notes, and snippets.

func scan(str string)[]string {
var head []string
var tail string
if str == "" {
return []string{}
}else{
x := string(str[0])
switch x {
case "'":
irb(main):132:0> str
=> "a b 'c d' e"
irb(main):133:0> scan(str)
=> ["a", "b", "c d", "e"]
package main
import "fmt"
import "os"
import "os/exec"
import "net/http"
func main() {
port := os.Args[1]
script := os.Args[2]
@koduki
koduki / fizzbuzz.rb
Created April 19, 2019 02:04
FizzBuzz with Pattern Match
(1..100).map do |i|
case [i % 3, i % 5]
in [0, 0]
"FizzBuzz"
in [0, _]
"Fiz"
in [_, 0]
"Buzz"
else
i.to_s
@koduki
koduki / JFRParser
Last active December 3, 2018 01:44
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cn.orz.pascal.tinybench;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@koduki
koduki / CharTest.java
Created November 21, 2018 15:25
UTF8から文字コード変換するときにSJISの範囲外の文字を任意の文字に置き換えるサンプル
String str = "a吉野屋𠮷野\r\n屋ア緣イ?";
// byte[] bytes = str.getBytes("Windows-31j");
char alt = '□';
final String charset = "Windows-31j";
String filteredStr = filterLowSurrogate(str);
String translatedStr = new String(str.getBytes(charset), Charset.forName(charset));
StringBuilder sb = new StringBuilder(filteredStr.length());
for (int i = 0; i < filteredStr.length(); i++) {
@koduki
koduki / TinyBenchmark.java
Last active October 14, 2018 02:36
Java 11でJMC/Flight Recorderが完全OSS化したのでJFR APIを使ったマイクロベンチマークツールのサンプル。解説は https://qiita.com/koduki/items/6e8fbcbafdcc2f743f56
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cn.orz.pascal.tinybench;
import java.io.IOException;
import java.nio.file.Path;
import java.text.ParseException;
@koduki
koduki / Base.java
Last active October 13, 2018 17:11
みんな大好きJavaの文字列結合に関して調べてみた。とりあえずコンパイラは結構仕事をしているみた。StringBuilder直より命令数少ないし、Java11だとさらなる最適化がされておる...
public static void checkJavacOptimizationPlus() {
String hello = "hello(v)";
String world = "world(v)";
final String HELLO = "hello(c)";
final String WOLRD = "world(c)";
String mixedStr2 = "hello(l)" + "world(l)" + HELLO + WOLRD + hello + world;
}
docker run -d --name zookeeper -p 2181:2181 confluent/zookeeper
docker run -it --name kafka -p 9092:9092 --link zookeeper:zookeeper confluent/kafka
kafka-topics --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: wf-exec-ml-
spec:
entrypoint: exec-ml
volumes:
- name: google-cloud-key
secret:
secretName: btc-prediction-key