Skip to content

Instantly share code, notes, and snippets.

@yuba
yuba / file0.java
Created March 10, 2016 00:01
継承関係があるのはわかる、で、どちらが親でどちらが子? ref: http://qiita.com/yuba/items/baceffbdbcfdc03f7945
class Real {
double r;
}
class Complex {
double r;
double i;
}
@yuba
yuba / Test.java
Created February 26, 2016 08:44
Java8ならinterfaceもメインクラスにできるぞ ref: http://qiita.com/yuba/items/ddf69793fe5708a36be6
interface Test {
static void main (String[] args){
System.out.println("hello, world.");
}
}
@yuba
yuba / file0.cpp
Created November 14, 2015 09:43
operator==()が定義してあればoperator!=()を書かなくてもよくするやつ ref: http://qiita.com/yuba/items/d352c4ba9b2d4bc10bbe
template<class T, class F = decltype(!(std::declval<T>()==std::declval<T>()))>
// 自動的に定義される!=演算子。==演算子の結果に!演算子を適用した結果を返します。
F operator!=(T a, T b)
{
return !(a==b);
}
@yuba
yuba / file0.cpp
Created November 11, 2015 05:30
std::set<T>の所属判定をスマートに書く ref: http://qiita.com/yuba/items/f06846ea9bb1147bf581
s.find(e) != s.end()
@yuba
yuba / file0.c
Created November 6, 2015 03:14
可変長構造体をmalloc()使わないで確保 ref: http://qiita.com/yuba/items/5e894ea9f12ba3fe354b
// つまり、長さ256の配列を確保するのに
int int_array[256];
// でなく
int* int_array = (int*)malloc(256);
// なんてやるのは
@yuba
yuba / file0.cpp
Last active November 4, 2015 13:14
バッファが足りないと結果が切り捨てられる文字列取得関数を自動リトライするユーティリティ関数 ref: http://qiita.com/yuba/items/fc9c677d45ed7889c884
// バッファが足りないと結果が切り捨てられる文字列取得関数を、バッファを拡大しながら呼び出し続けて全内容を取得します
template<typename TChar, typename PFunc, typename... TParams>
std::basic_string<TChar> challenge_get_string(PFunc f, TParams... params)
{
vector<TChar> buf(256);
size_t result_len;
for (;; buf.resize(buf.size() * 2))
{
result_len = f(params..., buf.data(), buf.size());
if (result_len < buf.size() - 1) break;
@yuba
yuba / regex_with_TCHAR.cpp
Created July 31, 2015 07:26
TCHARを使っているC++プロジェクトでC++11正規表現を使おうとするとこういうインクルードをすることになる
#include <regex>
namespace std {
#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wregex tregex;
typedef std::wsmatch tsmatch;
#else
typedef std::string tstring;
typedef std::regex tregex;
typedef std::smatch tsmatch;
@yuba
yuba / mackerel-agent.service
Last active August 29, 2015 14:23 — forked from nori-nori/gist:93f7a971d4e9bae9ac2c
fixed to require the network to be up.
[Unit]
Description=Mackerel Agent
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/mackerel-agent
ExecStart=/usr/local/bin/mackerel-agent --root=/var/lib/mackerel-agent $OPTS
[Install]
@yuba
yuba / customactions.xml
Last active August 29, 2015 14:08
Gitローカル変更の無視をSourceTreeからも ref: http://qiita.com/yuba/items/35459755e53035ed102f
<?xml version="1.0"?>
<ArrayOfCustomAction xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CustomAction>
<Caption>ローカルで管理対象外に</Caption>
<OpenInSeparateWindow>false</OpenInSeparateWindow>
<ShowFullOutput>false</ShowFullOutput>
<Target>git</Target>
<Parameters>update-index --skip-worktree $FILE</Parameters>
</CustomAction>
<CustomAction>
@yuba
yuba / file0.java
Created October 22, 2014 01:22
JavaでRDBデッドロック検出 ref: http://qiita.com/yuba/items/46e65d546ae3c723222b
try {
// 永続化操作
} catch (SQLException sqle) { // SQLExceptionを投げるフレームワークの場合
if ("40001".equals((sqle).getSQLState())) {
// デッドロック
}
else throw sqle;
} catch (PersistenceException pe) { // PersistenceExceptionを投げるフレームワークの場合
Throwable cause = pe.getCause();
if (cause instanceof SQLException && "40001".equals(((SQLException)cause).getSQLState())) {