Skip to content

Instantly share code, notes, and snippets.

@maraigue
maraigue / std_map_at.cpp
Created July 7, 2014 13:19
[C++] std::mapのconst参照に対して要素を取得するときには at(key) が使えますよ、という話(C++11標準、gccはそれ以前から実装)
#include <map>
#include <iostream>
#include <stdexcept>
class MyClass{
public:
typedef std::map<int, int> storage_type;
private:
storage_type value_;
@maraigue
maraigue / millionlive-6th-idol-colors.sparql
Created April 27, 2019 02:41
im@sparql (https://sparql.crssnky.xyz/imas/) 利用例:ミリオンライブ6thLIVE仙台公演(Angel)の出演者のアイドルカラーを得る
PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX imas: <https://sparql.crssnky.xyz/imasrdf/URIs/imas-schema.ttl#>
PREFIX imasrdf: <https://sparql.crssnky.xyz/imasrdf/RDFs/detail/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX math: <http://www.w3.org/2005/xpath-functions/math#>
PREFIX xsd: <https://www.w3.org/TR/xmlschema11-2/#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?色 ?名前 ?声優
@maraigue
maraigue / hatenagroup2movabletype.rb
Last active December 9, 2018 09:52
はてなグループからエクスポートしたXMLファイルを、MovableType形式に変換する
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'text/hatena'
require 'rexml/document'
AUTHOR = "BlogAuthor" # 著者名を入力してください
def check_node(node, expected_name)
case node
when REXML::Element
@maraigue
maraigue / opt-tail-recursion.h
Created July 3, 2011 16:05
「一言書くだけで末尾再帰最適化」をC++でやってみた
// 元ネタ:http://d.hatena.ne.jp/wasabiz/20110118/1295335821
//
// 注意点:
// ここで定義されているTCO_FUNCは、「末尾再帰で書かれた関数の引数が2つである場合」
// に限定された定義です。
// それ以上の場合は、別途マクロを定義しないとならないです。
// Boost.PPとかを使うと何とかなるのかな…?
#ifndef _OPT_TAIL_RECURSION_H_
#define _OPT_TAIL_RECURSION_H_
@maraigue
maraigue / cinderella-girls-name-prefix.rb
Last active November 2, 2018 18:44
シンデレラガールズのアイドル名を、手前から見て一致しているものが並ぶよう表示
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
strs = DATA.readlines
strs.each{ |line| line.chomp!; line.encode('utf-8') }
strs.uniq!
strs.sort!
width = strs.map{ |s| s.length }.max
parent_end = [0] * width
@maraigue
maraigue / xauth-twitter.rb
Created February 14, 2010 16:41
Requesting OAuth access token without browser, only with Twitter user name and password (so-called xAuth), by Ruby
#!/usr/bin/env ruby
# *** Important notification ***
# As xAuth is officially supported, we have to register
# your application needing xAuth, via e-mail.
# If not registered, 401 error will be returned.
# http://apiwiki.twitter.com/Twitter-REST-API-Method:-oauth-access_token-for-xAuth
#
# (*** 重要な告知 ***
# xAuthが公式にサポートされたのに伴い、xAuthの必要なアプリケーションは
@maraigue
maraigue / maze.rb
Created January 18, 2010 15:32
迷路を最短経路で脱出する問題
#!/usr/bin/ruby
# http://okajima.air-nifty.com/b/2010/01/post-abc6.html
# 【2010.1.25追記】
# #{RUBYLIB}/matrix.rb のコードを修正しないと動かないかもしれません。
# http://redmine.ruby-lang.org/issues/show/560
require 'set'
require 'matrix'
@maraigue
maraigue / README.md
Last active March 9, 2017 09:34
アイマスのアイドル名でしりとり(なるべく多くの人数を入れるようにする)

使い方

  1. http://chiraura.hhiro.net/shiritori/ を開きます。
  2. 「しりとりさせる単語集合」の欄に、「アイドル名一覧.txt」の内容を貼り付けます。「結果.txt」にある内容が得られます。

補足

濁点・半濁点はないものとしてしりとりします。

データについて

@maraigue
maraigue / starlight-stage-gekijou.rb
Last active February 25, 2017 08:03
デレステの劇場で登場したアイドルの回数を調べる(2017.2.25時点)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 基準
# - プロデューサーは数えない
# - ちひろさんは数える
# - セリフのみの登場も数える
require 'yaml'
@maraigue
maraigue / enum_random.rb
Created August 29, 2016 07:34
[Ruby] ArrayじゃなくてEnumerableでsample(ランダムにn要素を選ぶ)を使えるようにする
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# ArrayじゃなくてEnumerableでsample(ランダムにn要素を選ぶ)を使えるようにする。
# 例えば、大きいファイルから1行をランダムに抜き出すなど。
#
# 厄介なのは、要素の個数が最初からはわからないこと。
# 作戦としては以下の通り。
# - k個目の要素までを読み込んだとき、そのk個目の要素が選ばれているべき確率は
# n/k。なのでその確率で選ばれるかを決める。