Skip to content

Instantly share code, notes, and snippets.

@mattsan
mattsan / App.java
Created February 9, 2019 01:37
read a resource file with `Stupid Scanner Tricks`
package sample;
public class App {
public String getGreeting() {
return "Hello world.";
}
public static void main(String[] args) {
String yaml = readResource("/foo.yml");
System.out.println(yaml);
@mattsan
mattsan / App.java
Last active February 9, 2019 00:06
Java + Liquid
// src/main/java/sample/App.java
package sample;
import java.io.File;
import java.net.URL;
import liqp.Template;
public class App {
public static void main(String[] args) {
@mattsan
mattsan / App.java
Created February 8, 2019 23:46
Java + YAML
// src/main/java/sample/App.java
package sample;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
public class App {
public static void main(String[] args) {
try {
@mattsan
mattsan / sample_test.exs
Last active February 2, 2019 02:46
append a doukaku styled test case macro
defmodule TestMacro do
defmacro dtest(desc, input, expect) do
quote do
test unquote(desc) do
assert unquote(expect) == Sample.solve(unquote(input))
end
end
end
end
@mattsan
mattsan / orde29.prolog
Last active January 13, 2019 12:57
オフラインリアルタイムどう書く E29「アンエスケープ」を Prolog で解く
% orde29.prolog
%
% http://nabetani.sakura.ne.jp/hena/orde29unes/
%
% compiler:
% GNU-Prolog ( http://www.gprolog.org )
%
% compile:
% $ gplc --no-top-level orde29.prolog
%
@mattsan
mattsan / md2epub.rb
Created December 24, 2018 03:16
ブログ記事「Markdown から EPUB を作る」より
require 'redcarpet'
require 'nokogiri'
require 'securerandom'
require 'gepub'
Chapter = Struct.new("Chapter", :title, :body)
def split_md_into_chapters(source)
result = []
title = nil
@mattsan
mattsan / decode.prolog
Created December 23, 2018 04:27
偽クフ語解読器
% 偽クフ語解読器
% decode.prolog
% 規則
% 1. S -> U 011 U (U 'ならば' U)
s(LHS, RHS) :-
append(U1, [0'0, 0'1, 0'1 | U2], LHS),
u(U1, T_U1),
u(U2, T_U2),
@mattsan
mattsan / md2epub.rb
Created December 12, 2018 04:45
Generate a EPUB file from a Markdown file.
#!/usr/bin/env ruby
require 'pathname'
require 'thor'
require 'gepub'
require 'redcarpet'
class Md2EPub < Thor
default_command :pub
@mattsan
mattsan / orde29.ex
Last active December 9, 2018 02:21
オフラインリアルタイムどう書くE30「アンエスケープ 2018.12.8」を Elixir で解く
defmodule Orde29 do
@moduledoc """
オフラインリアルタイムどう書く E29
[アンエスケープ 2018.12.8](http://nabetani.sakura.ne.jp/hena/orde29unes/) を Elixir で解きました。
基本的なアイディアとしては [Ruby 版](https://github.com/mattsan/orde29_ruby) と同じです。
パース中に結果の文字列の内容をチェックして不正な結果になることがわかった時点で終了するようにしています。
`tail` は結果の文字列の末尾の文字なので冗長ですが、文字列の末尾の文字を取り出す手間が面倒だったので独立したパラメータで渡すようにしています。
 """
@mattsan
mattsan / my_range.ex
Created December 6, 2018 08:04
Elixir の Enumerable プロトコルを利用する検証コード(Range の自作)
defmodule MyRange do
@moduledoc """
自作の Range の実装
詳しくは [Enumerable protocol のドキュメント](https://hexdocs.pm/elixir/Enumerable.html)を参照。
"""
defstruct first: 0, last: 0
def new(first, last) do