This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXXFLAGS = -std=c++11 | |
default: | |
# make sample-{std-function,template} | |
sample-std-function: sample-std-function.cpp sample-std-function.hpp | |
$(CXX) $(CXXFLAGS) $< -o $@ | |
sample-template: sample-template.cpp sample-template.hpp | |
$(CXX) $(CXXFLAGS) $< -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rglpk" | |
# An example of solving mixed integer programming by rglpk (Ruby interface for GLPK) | |
# Original C-language-version by Masahiro Sakai | |
# https://gist.github.com/msakai/2450935/32efeace1ce27b2259b9792e8731436d7b0bb523 | |
# | |
# rglpk must be installed | |
# https://en.wikibooks.org/wiki/GLPK/Ruby | |
# Maximize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
class Hash | |
# hashobj[:hoge] を hashobj.hoge でもアクセス可能にする | |
# ・値の読み取りはどんなキーでも対象 | |
# ・値の書き込みはすでに存在するキーのみ対象 | |
# ・すでに存在するメソッドと名前が重複した場合は、 | |
# すでに存在するメソッドへのアクセスが優先される | |
# ・当該名称のキーがStringとSymbolの両方で存在する場合は例外 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OpenShogiLib version 0.4.2 の簡単なサンプル | |
// http://gps.tanaka.ecc.u-tokyo.ac.jp/gpsshogi/index.php?OpenShogiLib | |
// | |
// ライブラリのインストール方法(APTが使える場合) | |
// sudo apt-get install libosl-dev libosl-doc | |
// ※libosl-docも導入を推奨。Webに上がっているリファレンスは古いので。 | |
// ※自前でソースコードからコンパイルする場合、Boostを導入した上で行う必要が | |
// あります。 | |
#include <osl/state/simpleState.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
※日本語の解説: http://blog.livedoor.jp/maraigue/archives/1689443.html | |
A zsh script for showing "[git]" in the prompt if you are a git repository directory | |
If NOT in a git repository directory, the prompt will be: | |
<USERNAME@HOSTNAME CURRENTDIR>$ | |
If in a git repository directory, the prompt will be: | |
<USERNAME@HOSTNAME CURRENTDIR>[git]$ | |
If in a remote directory (e.g. SSH-logged-in), the prompt will be: | |
<USERNAME@HOSTNAME CURRENTDIR>[remote]$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------- definition ---------- | |
class Object | |
def define_singleton_method(name, method = nil, &block) | |
unless !!(method) ^ !!(block) | |
raise ArgumentError, "Only one method should be given" | |
end | |
source_object = self | |
Module.new do | |
define_method(name, method || block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
これをg++でコンパイルすると | |
find2.cpp: 関数 ‘TYPE str2num(std::string&) [with TYPE = int, std::string = std::basic_string<char>]’ 内: | |
find2.cpp:17:20: instantiated from here | |
find2.cpp:7:28: エラー: ‘iss’ has incomplete type | |
というエラーになる。 | |
#include <sstream> を加えると解決する。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# Rubyのソースコードを与えると、同じ働きをする | |
# 「(」・ω・)」うー!(/・ω・)/にゃー!」だらけの | |
# コードを出力するプログラム | |
# | |
# Ruby1.9系列限定、文字コードは1種類に統一する必要あり | |
# | |
# 元ネタ(JavaScript版): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# その1: http://gist.github.com/2802312 | |
class Proc | |
def rescue(klass, value) | |
begin | |
self.call | |
rescue klass | |
return value | |
end | |
end |