Skip to content

Instantly share code, notes, and snippets.

@yuba
yuba / file0.css
Created June 11, 2014 02:12
Redmine上の文書をまともに印刷できるようユーザーCSSを作りました ref: http://qiita.com/yuba/items/182174d51875d4a79c7a
@media print {
body {
font-family: serif;
font-size: 16px;
line-height: 1.6em;
color: #000;
}
ul,ol {
margin-bottom: 0 !important;
}
@yuba
yuba / wpad.dat
Created June 11, 2014 03:59
社内ネットにつないだときだけプロクシ設定をオンにする ref: http://qiita.com/yuba/items/2840f913194732a30bd4
function FindProxyForURL(url,host)
{
if ( isPlainHostName(host)
|| shExpMatch(host, "172.16.*")
|| shExpMatch(host, "172.17.*")
|| shExpMatch(host, "172.18.*")
|| shExpMatch(host, "172.19.*")
|| shExpMatch(host, "172.2?.*")
|| shExpMatch(host, "172.30.*")
|| shExpMatch(host, "172.31.*")
@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())) {
@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 / 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 / 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 / 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 / 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
Created November 11, 2015 05:30
std::set<T>の所属判定をスマートに書く ref: http://qiita.com/yuba/items/f06846ea9bb1147bf581
s.find(e) != s.end()
@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);
}