Skip to content

Instantly share code, notes, and snippets.

View tyru's full-sized avatar
🏠
Working from home

Fujiwara Takuya tyru

🏠
Working from home
View GitHub Profile
@tyru
tyru / test.pl
Last active September 7, 2018 00:34
Tree library in Prolog (tested in SWI-Prolog)
:- consult(tree).
:- use_module(tree).
:- begin_tests(tree).
test(new_tree1) :-
new_tree(top, top++[]).
test(new_tree2) :-
new_tree(node++[], node++[]).
@tyru
tyru / vimscript-ast-to-prolog.go
Created August 27, 2018 19:06
Vim script AST dumper to Prolog syntax, using github.com/haya14busa/go-vimlparser
package main
import (
"bytes"
"fmt"
"io"
"os"
"strconv"
"strings"
[1] ?- eval(add(tInt(1), tInt(2)), R).
R = tInt(1+2).
[1] ?- eval(let(T, =, add(tInt(1), tInt(2))), R).
T = tInt(1+2),
R = tVoid.
[1] ?- eval(let(T, =, add(T2, tInt(2))), R).
T = tInt(_8418+2),
T2 = tInt(_8418),
@tyru
tyru / color.ts
Created August 3, 2018 06:01
Simple CSS Color class in TypeScript
export default class Color {
private static cache = new Map<string, Color>();
// https://developer.mozilla.org/ja/docs/Web/CSS/color_value
public static readonly BLACK = Color.fromRGB(0, 0, 0);
public static readonly SILVER = Color.fromRGB(192, 192, 192);
public static readonly GRAY = Color.fromRGB(128, 128, 128);
public static readonly WHITE = Color.fromRGB(255, 255, 255);
public static readonly MAROON = Color.fromRGB(128, 0, 0);
@tyru
tyru / prompt-buffer.vim
Created June 3, 2018 16:29
:set buftype=prompt
function! s:run() abort
new
setlocal buftype=prompt
function! s:TextEntered(text)
if a:text == 'exit' || a:text == 'quit'
stopinsert
close
else
call append(line('$') - 1, 'Entered: "' . a:text . '"')
" Reset 'modified' to allow the buffer to be closed.
@tyru
tyru / import-qf.vim
Created April 20, 2018 15:04
:ImportQF to import the output of shell command as quickfix-list or location-list
command! -nargs=+ -complete=shellcmd ImportQF call s:import_qf(<q-args>, -1)
command! -nargs=+ -complete=shellcmd LImportQF call s:import_qf(<q-args>, winnr())
function! s:import_qf(shellcmd, winnr) abort
if a:winnr >=# 0
call setloclist(
\ a:winnr, [], 'r', {'lines': systemlist(a:shellcmd)}
\)
else
call setqflist(
@tyru
tyru / volt-json-dsl.md
Last active April 15, 2018 14:26
Volt リファクタリングメモ (JSON DSL の導入)
@tyru
tyru / err.go
Last active March 31, 2018 17:48
package main
import (
"errors"
"fmt"
multierror "github.com/hashicorp/go-multierror"
)
func main() {
@tyru
tyru / check-helptags.vim
Created March 19, 2018 14:02
(picked from my old repository)
function! s:run() abort
mark Z
let winnum = winnr('$')
let noexist = []
let keywords = uniq(sort(s:get_all_matches(join(getline(1, '$'), "\n"), '|\zs[^|]\{-1,}\ze|')))
let allnum = len(keywords)
let i = 1
echon "\rChecking..."
for keyword in keywords
try
@tyru
tyru / list-func.vim
Last active March 3, 2020 05:57
fold() and flatmap() implementation in Vim script
function! s:fold(list, f, init) abort
let ref = {'result': a:init}
return map(copy(a:list), {_,v -> extend(ref, {'result': a:f(ref.result, v)})})[-1].result
endfunction
function! s:fold2(list, f, init) abort
let l = a:list + [a:init]
let end = len(a:list)
return map(l, {i,v -> i is# end ? l[i-1] : a:f(l[i-1], v)})[-1]
endfunction