Skip to content

Instantly share code, notes, and snippets.

View ochaochaocha3's full-sized avatar

Kosuke Yamashita ochaochaocha3

View GitHub Profile
@ochaochaocha3
ochaochaocha3 / array_to_hash.rb
Created February 5, 2015 08:00
配列からハッシュを作るやり方いろいろ
a = [1, 2, 3]
# Hash.[] <- とても読みにくい
h1 = Hash[
a.map { |x| [x, "value#{x}"] }
]
# => {1=>"value1", 2=>"value2", 3=>"value3"}
# 手続き型言語っぽい書き方
h2 = {}
@ochaochaocha3
ochaochaocha3 / lunch.erl
Last active August 29, 2015 14:15
Erlang で家計簿の穴埋め
-module(lunch).
-export([calc/0]).
calc() ->
NDays = 7,
TotalInThePeriod = 2290,
Menus = [{set, 370}, {curry, 350}, {udon, 300}],
Seq = lists:seq(0, NDays),
Amounts = [[X, Y, Z] ||
X <- Seq, Y <- Seq, Z <- Seq, X + Y + Z =:= NDays],
@ochaochaocha3
ochaochaocha3 / tiarra.conf
Created February 22, 2015 14:18
Tiarra の Upstart 設定
description "Tiarra"
author "ocha <ochaochaocha3@example.net>"
start on runlevel [2345]
stop on runlevel [016]
exec start-stop-daemon --start --chuid irc --chdir /home/irc/tiarra --exec tiarra
respawn # 異常終了時に再起動する
@ochaochaocha3
ochaochaocha3 / roll_parser.log
Last active August 29, 2015 14:16
ダイスロール構文解析器
"1"
[Parse tree]
{:int=>"1"@0}
[Result]
1
"1+2"
@ochaochaocha3
ochaochaocha3 / detatoko_spec.rb
Created March 16, 2015 06:04
でたとこ spec テンプレ
# vim: fileencoding=utf-8
require_relative '../../../spec_helper'
require 'rgrb/plugin/detatoko/generator'
describe RGRB::Plugin::Detatoko::Generator do
let(:generator) { described_class.new }
describe '#skill_decision' do
context '〜の場合' do
@ochaochaocha3
ochaochaocha3 / calc.rb
Created March 21, 2015 15:00
Parslet で電卓(途中)
# vim: fileencoding=utf-8
require 'pp'
require 'parslet'
# require_relative 'calc_nodes'
# 計算機モジュール
module Calc
class BinaryOpNode
@ochaochaocha3
ochaochaocha3 / Makefile
Created April 2, 2015 14:33
atheme/po/Makefile を簡単に翻訳
# Short KISS instructions:
# 簡単な説明:
#
# - To add new languages: Add *.po target to LOCALES Make variable below
# 言語を追加するには: 下の LOCALES 変数に *.po ターゲットを追加する
# - Update and merge .po-files: make update-po
# .po ファイルを更新・マージする: make update-po
# - Only update the template .pot-file only: make update-pot
# テンプレート .pot ファイルのみを更新する: make update-pot
# - Run update-potfiles.sh when any new sourcefiles with translatable strings
@ochaochaocha3
ochaochaocha3 / gen-alter-ss-dssp.rb
Created April 3, 2015 03:52
DSSP で求めた二次構造を反映させる PyMOL スクリプトを自動生成する
# DSSP で求めた二次構造を反映させる PyMOL スクリプトを生成する
# アミノ酸残基を表すクラス
class Residue
# 鎖
attr_reader :chain
# 残基番号
attr_reader :num
# 二次構造
attr_reader :ss
@ochaochaocha3
ochaochaocha3 / Makefile
Created April 10, 2015 09:39
音を鳴らすテスト
sound: sound.c
gcc -o sound $^ -lm
@ochaochaocha3
ochaochaocha3 / calc.erl
Created June 6, 2015 15:29
「すごい Erlang ゆかいに学ぼう!」第 8 章の逆ポーランド記法計算機
%% 逆ポーランド記法計算機
-module(calc).
-export([rpn/1, rpn_test/0]).
%% RPN 電卓
rpn(L) when is_list(L) ->
case
lists:foldl(fun rpn/2, [], string:tokens(L, " "))
of