Skip to content

Instantly share code, notes, and snippets.

View kentaro's full-sized avatar

Kentaro Kuribayashi kentaro

View GitHub Profile
@kentaro
kentaro / attre_accessor.ex
Last active January 31, 2022 23:47
Generate accessors for module attributes in Elixir
defmodule AttrAccessor do
defmacro __using__(opts) do
quote do
unquote(opts[:attrs])
|> Enum.each(fn attr ->
Module.register_attribute(unquote(opts[:target]), attr, persist: true)
end)
def method_missing(func, _args) do
if value = __MODULE__.__info__(:attributes)[func] do
// Amazonの注文履歴をCSV形式にして出力するスクリプト
//
// 以下のスクリプトを参考に作成されました。
// http://moroya.hatenablog.jp/entry/2013/06/03/225935
//
// CSVに成型しているのは14行目から定義されているformatEntryという関数なので、これを書き換えれば自由な書式で出力できます。
(function(){
// 各注文履歴をCSVフォーマットにして返す
var datePattern = new RegExp("(\\d{4})年(\\d{1,2})月(\\d{1,2})日");
@kentaro
kentaro / cf.rb
Last active March 20, 2016 16:23
mruby-changefinderを試すよ
cf = ChangeFinder.new(5, 0.01, 10, 0.01, 5)
File.open('result.tsv', 'w') do |f|
File.open('go.tsv').each do |line|
date, trend = line.chomp.split("\t")
score = cf.score(trend.to_f)
f.puts("#{date}\t#{trend}\t#{score}")
end
end
@kentaro
kentaro / idea.yml
Last active January 20, 2016 08:05
---
service: minne
enable:
- h2
- mruby
mrbgems:
- mruby-foo
- mruby-bar
ssh-dss AAAAB3NzaC1kc3MAAACBALKU5LjbamBINmO3KZzxuYNi+C8Opwv5BJUAAUdFi8sZOTaYGsxLsds4fbtVuIt1DuBos1e+WC5imk5d57ExFhzsseMxdqtNTLR52rGwJViFNqmlGfrU2SGiUYXEg+UMCJx3CdEG1exmoexdmmPl+b3OIeeEARuhg325rVurOlRLAAAAFQC/20nsxM8DbBvP/TfCD2wSbDUqDQAAAIAE5VYx2KxQ1kqpB7Zpxslgc45e/lxtrzUTJA2+shQFdaqkY44uNrWGtdvlir0gawyNqn7APZLVnJyH1Ev7jnHI+Stvp9o8cV5ssTQqfsO5769upxnv5cFfv4/lYc8nEht3OgEp8k5zZ0twIYMV2vuVtZYjOGfezlL+1WayjEkvEQAAAIEAo3elqUk/3L5gr8HIutDPz3zwlyz5Djb6m7xGYro4b/EXV599X9Tn0LozrGITHdl62UZmppNDn3iAfLa+oNfr2CmEDGTy0FBJsNVevJFH0B0lHlE4HcCNWvjDZa9Y5bPMTt0BEBrQTXZEk2Sth7ocstpfv7yGanaUyeMKC8aYh3c= antipop@kuribayashi-kentarou-no-macbook.local
@kentaro
kentaro / gist:7520653
Last active December 28, 2015 15:19
bool型ぽいもののオブジェクトをデバッグログ用にする例(Perl)
#!/usr/bin/env perl
use strict;
use warnings;
package Debug;
sub new {
my ($class, $flag) = @_;
bless \$flag, $class;
@kentaro
kentaro / gist:7320423
Created November 5, 2013 15:08
はじめてのVim script
function! GitBrowseRemoteAtLine()
ruby << EOF
`git browse-remote -L#{VIM::Window.current.cursor.first} -- #{VIM::Buffer.current.name}`
EOF
endfunction
:command! GitBrowseRemoteAtLine :call GitBrowseRemoteAtLine()
" vim-automatic
let g:automatic_config = [
\ {
\ "match" : {
\ "filetype" : "help",
\ "buftype" : "help",
\ },
\ "set" : {
\ "height" : "50%",
\ "move" : "bottom",
@kentaro
kentaro / gist:6958739
Last active December 25, 2015 09:59
supervisord configuration sample
[program:program_name]
command = plackup ...
process_name = %(program_name)s
user = user_name
environment = HOME=/home/user_name
directory = /app/program_name
stdout_logfile = /var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes = 50MB