Skip to content

Instantly share code, notes, and snippets.

@mutsune
mutsune / CustomStringEscapeUtil.java
Created December 6, 2018 03:46
(Part of) custom apache commons StringEscapeUtil like PHP htmlspecialchars
final private static CharSequenceTranslator quotes = buildAggregateTranslator(Mode.ENT_QUOTES);
final private static CharSequenceTranslator noquotes = buildAggregateTranslator(Mode.ENT_NOQUOTES);
private static AggregateTranslator buildAggregateTranslator(Mode mode) {
Map<CharSequence, CharSequence> map = new HashMap<>();
if (mode == Mode.ENT_QUOTES) {
map.put("\"", "&quot;"); // " - double-quote
map.put("'", "&apos;"); // ' - apostrophe
}
@mutsune
mutsune / gcstat.sh
Created December 6, 2018 03:42
Number of GC events and GC time **per day**
#!/usr/bin/env bash
set -e
# Java process ID
PID="$(pgrep java)"
# convert `ps -o etime` output format to second
function psetime_converter() {
echo "$(cat -)" | awk '
@mutsune
mutsune / psetime_converter.awk
Created October 17, 2018 07:40
Convert `ps -o etime` format into seconds https://stackoverflow.com/a/14653443
#!/usr/bin/awk -f
BEGIN { FS = ":" }
{
if (NF == 2) {
print $1*60 + $2
} else if (NF == 3) {
split($1, a, "-");
if (a[2] != "" ) {
print ((a[1]*24+a[2])*60 + $2) * 60 + $3;
} else {
package sax;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import java.io.File;
@mutsune
mutsune / play_next_on_end.js
Last active October 13, 2018 13:01
次の audio を自動再生する
const tunes = document.querySelectorAll('audio');
tunes.forEach((e, i) => e.onended = () => tunes[i + 1].play());
@mutsune
mutsune / client.js
Created September 21, 2018 15:21
minimum socket-io
const socketio = require('socket.io-client')
const socket = socketio('http://localhost:8888');
socket.on('update', d => console.log(d));
socket.on('dynamo', d => console.log(d));
// socket.on('connect', function(){});
// socket.on('event', d => console.log(d));
// socket.on('disconnect', function(){});
import java.io.File
object TrainSampleWithScala extends App {
def train() {
val parameter: Parameter = new Parameter(SolverType.AVERAGE, 10)
val model: PerceptronModel = PerceptronModel.train(docs, parameter)
return model
}
@mutsune
mutsune / file.c
Last active May 17, 2018 13:46
はじめてのOSコードリーディング リスト10.1 ファイル操作のサンプルコード
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd;
char buf[2];
fd = open("filename.txt", 2);
@mutsune
mutsune / lang.c
Last active April 30, 2018 08:53
「ポーランド記法での四則演算」「関数定義とその実行」「関数の再帰呼び出し」を処理できる minimal な言語処理系の実装 https://www.youtube.com/watch?v=JAtN0TGrNE4
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
static char *p;
static char func[26][100];
__attribute__((noreturn)) static void error(char *fmt, ...) {