動かざることバグの如し

近づきたいよ 君の理想に

Macでvagrant box add ができない

環境

症状

オレオレboxを生成する

vagrant package --output hogehoge.box

boxをリストに追加する

vagrant box add hogehoge hogehoge.box

は???????????

An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

原因

バグ

対処法

/opt/vagrant/embedded/bin/curlcurl_bckとかにして避難させる でもう一度

なお vagrant 1.9以降ではバグ治ってる模様

参考

https://github.com/mitchellh/vagrant/issues/6725

macでデカいzipが解凍できない

症状

数GB規模の巨大なzipファイルをunzipコマンドで解凍しようとすると失敗する

% unzip 2015-09-24-raspbian-jessie.zip
Archive:  2015-09-24-raspbian-jessie.zip
warning [2015-09-24-raspbian-jessie.zip]:  76 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [2015-09-24-raspbian-jessie.zip]:  reported length of central directory is
  -76 bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1
  zipfile?).  Compensating...
   skipping: 2015-09-24-raspbian-jessie.img  need PK compat. v4.5 (can do v2.1)

note:  didn't find end-of-central-dir signature at end of central dir.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

解決策1

実はtarコマンドでもzipファイルを解凍できる マジか

tar xvf 2015-09-24-raspbian-jessie.zip

解決策2

このコマンドはMac OS専用っぽい

ditto 2015-09-24-raspbian-jessie.zip

owncloudを高速化メモ

cronの見直し

デフォルトではページ開くたびに更新が発生するっぽい()

素直にCrontabで定期的に実行させたほうがよさげ

apacheユーザーでcrontabを開く

sudo crontab -u www-data -e

以下追加

* * * * * php -f /var/www/owncloud/cron.php

owncloud側の発火するタイミングの設定をAjaxからCronへ変更

sudo -u www-data /var/www/owncloud/occ background:cron

OPcache

インストール

apt install php7.0-opcache php7.0-apcu

php.iniに以下追記 デフォルトだとPHPの設定が /etc/php/7.0/cli/php.ini のはず 

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=2000
opcache.revalidate_freq=600
opcache.fast_shutdown=1

[apc]
apc.enabled=1
apc.shm_size=64M
apc.ttl=3600
apc.gc_ttl=3600

設定の意味とかはココとか参考に

owncloudの ROOT/config/config.phpに以下追記

'memcache.local' => '\OC\Memcache\APCu',

これでApache再起動

ログの出力設定

直接高速化と関係するわけじゃないけど原因を知るにはまずログからって言うし

config.phpに以下追記

$CONFIG = array (
  'logtimezone' => 'Asia/Tokyo',
  'logdateformat' => 'Y-m-d H:i:s',
  'logfile' => '/var/log/owncloud/owncloud.log',
  );

ForkしたレポジトリでFork元のプルリクエストをマージしたい

タイトル意味不だけど間違ってはいない

Githubでほしいマージリクエストがあるけどマージされてない場合、フォークして自分のレポジトリ内でマージしたいってやつ。

git fetch origin pull/【fork元のプルリクID】/head:【ローカルで作りたいブランチ名】

でいける

手順

  • forkする
  • ローカルにgit cloneする
  • remoteにfork元のレポジトリを追加する 仮に「origin2」とする
  • git fetch origin pull/22/head:fix_issue33

公式ドキュメント

Checking out pull requests locally - User Documentation

Railsでカラム名「hash」を含むデータベースを扱う

そもそも

Railsではカラム名「hash」を含むデータベースにアクセスしようとするとエラーになる。

hash is defined by ActiveRecord

つまりActiveRecord様がもう予約語として確保してしまったから無理!テメーがカラム名変えろよってエラー

対処1

さすがRails、すでにそれ専用のGemがある

github.com

インストールは safe_attributes を加えるだけ、使うときは

class MyModel < ActiveRecord::Base
  bad_attribute_names :hash
end

ってやるだけ。簡単じゃん

対処2

だが上記のGemには1つ欠点がある。全くメンテナンスされてない(平成28年10月24日現在4年以上更新されていない)

要はinstance_method_already_implemented見てるだけだからそこハックすればよくね?って話

  # hashが予約語なので回避 
  def self.instance_method_already_implemented?(method_name)
    return true if method_name == 'hash'
    super
  end

いやカラム名変えろって話ですよね、はい