<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Waza Lab</title>
    <description></description>
    <link>https://www.wazalab.com/</link>
    <atom:link href="https://www.wazalab.com/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>heroku pg:diagnoseをslackに投げる方法</title>
        <description>&lt;p&gt;年末の休暇でコード変更がなかったのが原因かわからないが、herokuのpostgresが謎のout of memoryを吐いて止まりまくる現象が起きた。
しかも、成人の日の三連休中で対応が遅れてしまった。問題が当日わからなかったので、プロセスを再起動などの処理をして、1日様子見。
そして、次の日も問題がお昼ごろに起きたので、follower DBをマスタに切り替えて問題は治った。&lt;/p&gt;

&lt;p&gt;週末にherokuに問い合わせたものが火曜日に返信がきた。問題は、CPUがバーストしてたのが原因のこと。
モニタしていなかったので、一日に何回かheroku pg:diagnoseを叩き、それをslackに送るワンライナーを書いた。&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;heroku pg:diagnose &lt;span class=&quot;nt&quot;&gt;--app&lt;/span&gt; APP_NAME | curl &lt;span class=&quot;nt&quot;&gt;-X&lt;/span&gt; POST &lt;span class=&quot;nt&quot;&gt;--data-urlencode&lt;/span&gt;   &lt;span class=&quot;s2&quot;&gt;&quot;payload={&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&amp;lt;/dev/stdin&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;}&quot;&lt;/span&gt; https://hooks.slack.com/services/xxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;cronに設定しようとしたら動かない。。仕方がないのでshellを書いたら動いた。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#!/bin/bash -x

out=`/snap/bin/heroku pg:diagnose --json --app APP_NAME | /usr/bin/jq -r '.checks[] | {&quot;name&quot;: .name, &quot;result&quot;: .results} | select(.name |test(&quot;Burst&quot;))' | egrep 'name|balance' | sed s/\&quot;//g 2&amp;gt;&amp;amp;1`
echo $out 
curl -X POST --data-urlencode &quot;payload={\&quot;text\&quot;: \&quot;$out\&quot;}&quot; https://hooks.slack.com/services/T02xxxxxxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Thu, 20 Jan 2022 01:34:00 +0000</pubDate>
        <link>https://www.wazalab.com/heroku-pg-diagnose-output-to-slack</link>
        <guid isPermaLink="true">https://www.wazalab.com/heroku-pg-diagnose-output-to-slack</guid>
      </item>
    
      <item>
        <title>apt updateができない(postgresのところで止まる)ときの対処法</title>
        <description>&lt;p&gt;Ubuntu14のサーバがあり、Certbotが下記のエラーで更新できないでいた。&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Plugins selected: Authenticator nginx, Installer nginx                                                                                              
Attempting to renew cert &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;xxxxxxx.com&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; from /etc/letsencrypt/renewal/xxxxx.com.conf produced an unexpected error: &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;bad handshake: Error
([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)&quot;&lt;/span&gt;,&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; Skipping.                                                     
All renewal attempts failed. The following certs could not be renewed:                                                                              
  /etc/letsencrypt/live/xxxxxxy.com/fullchain.pem &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;failure&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;                                                                                                                                                       
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;単純にバージョンが古いと思い、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt update&lt;/code&gt;だがしかし、Postgresのところで止まる。。&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Err http://apt.postgresql.org trusty-pgdg/main amd64 Packages                                                                                       
  404  Not Found &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;IP: 147.75.85.69 80]                                                                                                              
Ign http://apt.postgresql.org trusty-pgdg/main Translation-en_US                                                                                    
Ign http://apt.postgresql.org trusty-pgdg/main Translation-en                                                                                       
W: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/trusty-pgdg/main/binary-amd64/Packages  404  Not Found &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;IP: 147.75.85.69 80]  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;古いのを使っているのは知っている。これを消す方法をググって、格闘すること30分。 /etc/apt/sources.list.d/pgdg.listを変更する方法でスキップできた。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# vi /etc/apt/sources.list.d/pgdg.list
# comment out the line 
# deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

# then,
# apt update ## works!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;certbotも&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt upgrade certbot&lt;/code&gt;したら動くようになった。&lt;/p&gt;
</description>
        <pubDate>Fri, 10 Dec 2021 06:34:00 +0000</pubDate>
        <link>https://www.wazalab.com/how-to-fix-apt-update-failure-due-to-postgres-on-the-old-ubuntu</link>
        <guid isPermaLink="true">https://www.wazalab.com/how-to-fix-apt-update-failure-due-to-postgres-on-the-old-ubuntu</guid>
      </item>
    
      <item>
        <title>[Rails] すべてのbooleanカラムの値を変更する方法</title>
        <description>&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;DEPRECATION WARNING: &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;.represent_boolean_as_integer&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; is now always &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;, so setting this is deprecated and will be removed &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;Rails 6.1
&lt;span class=&quot;c&quot;&gt;# Due to config.active_record.sqlite3.represent_boolean_as_integer = true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Rails6にアップグレードしたらSQliteのデフォルトboolean値の取扱い方が変わったみたい。
なにやら全ての値を変更せねばならず、大変だと思ったので自動化するスクリプトを書いた。&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;Rails&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eager_load!&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ApplicationRecord&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;descendants&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;collect&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;col_hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;const_get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;columns_hash&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;col_hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;col_hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:boolean&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;const_get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; = 't'&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sym&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;const_get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; = 'f'&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_sym&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Mon, 22 Nov 2021 06:34:00 +0000</pubDate>
        <link>https://www.wazalab.com/rails-how-to-change-all-attributes-where-its-type-is-boolean</link>
        <guid isPermaLink="true">https://www.wazalab.com/rails-how-to-change-all-attributes-where-its-type-is-boolean</guid>
      </item>
    
      <item>
        <title>Node app(redashbot)をsystemdで起動する方法</title>
        <description>&lt;p&gt;Redash botが使用できなくなったので、代替を探していたら&lt;a href=&quot;https://github.com/hakobera/redashbot&quot;&gt;redashbot&lt;/a&gt;を見つけて早速導入。
(Redashは買収後元気ありませんね。。)&lt;/p&gt;

&lt;p&gt;導入後Rebootに耐えたいよね、ってことでsystemdに登録してみた。以下手順。&lt;/p&gt;

&lt;h3 id=&quot;serviceファイル作成&quot;&gt;serviceファイル作成&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; $ sudo vi /etc/systemd/system/redashbot.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;中身は、&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Unit]
Description=Redashbot

[Service]
PIDFile=/tmp/redashbot.pid
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/home/ubuntu/redashbot
EnvironmentFile=/home/ubuntu/redashbot/bot.env
ExecStart=npm start
User=ubuntu
Group=ubuntu

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;bot.envは、&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SLACK_BOT_TOKEN=xxxx
REDASH_HOST=yyy
SLACK_BOT_TOKEN=
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;systemdにセットしてスタート&quot;&gt;systemdにセットしてスタート&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; $ sudo systemctl daemon-reload
 $ sudo systemctl start redashbot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;reboot後も起動するようにする&quot;&gt;Reboot後も起動するようにする&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; $ sudo systemctl enable redashbot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Thu, 28 Oct 2021 00:00:00 +0000</pubDate>
        <link>https://www.wazalab.com/add-node-app-to-systemd</link>
        <guid isPermaLink="true">https://www.wazalab.com/add-node-app-to-systemd</guid>
      </item>
    
      <item>
        <title>AWS ELBのSecurity Groupの設定方法</title>
        <description>&lt;p&gt;ELB/ALBの下にサーバを配置するときにどのセキュリティグループにするかいつもわからなくなるのでメモ。
構成はシンプルで&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ELB(https) -&amp;gt; Web(80)&lt;/code&gt;。&lt;/p&gt;

&lt;h3 id=&quot;elbのsecurity-group&quot;&gt;ELBのSecurity Group&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Inbound: HTTPS Custom 0.0.0.0/0&lt;/li&gt;
  &lt;li&gt;Outbound: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebのSecurity Group&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;webのsecurity-group&quot;&gt;WebのSecurity Group&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Inbound: HTTP Custom 172.31.0.0/16 (VPCのサブネット)&lt;/li&gt;
  &lt;li&gt;Outbound: all, custom 0.0.0.0/0&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Wed, 27 Oct 2021 00:00:00 +0000</pubDate>
        <link>https://www.wazalab.com/aws-security-group-for-elb</link>
        <guid isPermaLink="true">https://www.wazalab.com/aws-security-group-for-elb</guid>
      </item>
    
      <item>
        <title>Firebase storageのセキュリティ</title>
        <description>&lt;p&gt;FirebaseのAPIを使ってアップロードした場合、&lt;/p&gt;
&lt;blockquote&gt;https://firebasestorage.googleapis.com/v0/b/&amp;lt;project&amp;gt;.appspot.com/o/users%2F91b11d904a5f0eb398a334ssb5%2Fimages%2F60.jpg?alt=media&amp;amp;token=5908a2d0-7630-4a35-8be5-e3cc8adbd723&lt;/blockquote&gt;
&lt;p&gt;&lt;br /&gt;
のようなtoken付きのlinkをgetDownloadLinkで取得できる。このトークンがあると、誰でもダンロードできてしまう。
ダウンロード対象のダウンロードオブジェクトがセキュリティに気を使わなくてよいなら、tokenごとDBに保存。そうでない場合は、ref(path)だけ保存しておいて、クライアント側で毎回getDownloadLinkするのが良さそうだ。&lt;/p&gt;
</description>
        <pubDate>Thu, 26 Aug 2021 05:11:01 +0000</pubDate>
        <link>https://www.wazalab.com/2021/08/26/firebase-storage%e3%81%ae%e3%82%bb%e3%82%ad%e3%83%a5%e3%83%aa%e3%83%86%e3%82%a3/</link>
        <guid isPermaLink="true">https://www.wazalab.com/2021/08/26/firebase-storage%e3%81%ae%e3%82%bb%e3%82%ad%e3%83%a5%e3%83%aa%e3%83%86%e3%82%a3/</guid>
      </item>
    
      <item>
        <title>sqlite3でカラムを削除する方法 [SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE &amp;#8220;users&amp;#8221;]</title>
        <description>&lt;p&gt;Railsのマイグレーションでcolumnを追加後にrollbackすると下記のようなエラーができることがある。sqliteにはカラムを削除する方法がないので、一旦テーブルを消して作り直すのだが、外部キー制約のため削除できず、エラーになる。&lt;/p&gt;
&lt;pre class=&quot;theme:dark-terminal lang:sh decode:true&quot;&gt;== 20210802023517 AddJtiToUser: reverting =====================================
-- remove_index(:users, {:column=&amp;gt;:jti})
   -&amp;gt; 0.0022s
-- remove_column(:users, :jti, :string)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE &quot;users&quot;


Caused by:
ActiveRecord::InvalidForeignKey: SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE &quot;users&quot;だ&lt;/pre&gt;
&lt;p&gt;だが、しかしsqlite3.35でカラム削除ができるようになったので、最新バージョンを使えば良い。手元のubuntuのsqlite3は、3.31だったので、ソースからコンパイルする。&lt;/p&gt;
&lt;pre class=&quot;theme:dark-terminal lang:sh decode:true&quot;&gt;$ wget https://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
$ tar zxvf sqlite-autoconf-3360000.tar.gz 
$ cd sqlite-autoconf-3360000/
$ ./configure 
$ make&lt;/pre&gt;
&lt;p&gt;でこのバージョンを使って、&lt;/p&gt;
&lt;pre class=&quot;theme:dark-terminal lang:sh decode:true&quot;&gt;$ sqlite-autoconf-3360000/sqlite3 ~/my_project/db/development.sqlite3

# delete index and then drop column

sqlite&amp;gt; drop index index_users_on_jti;
sqlite&amp;gt; ALTER TABLE users DROP COLUMN jti;

&lt;/pre&gt;
&lt;p&gt;その後、Railsの場合、migration version を消すとrollbackしたことになる。&lt;/p&gt;
&lt;pre class=&quot;theme:dark-terminal lang:sh decode:true&quot;&gt;$ rails db:migrate:status | tail -n 2
   up     20210802023517  Add jti to user

$ sqlite3 db/development.sqlite3
&amp;gt; delete from schema_migrations where version='[version_number]';&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
</description>
        <pubDate>Wed, 04 Aug 2021 08:53:01 +0000</pubDate>
        <link>https://www.wazalab.com/2021/08/04/sqlite3%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%a0%e3%82%92%e5%89%8a%e9%99%a4%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95-sqlite3constraintexception-foreign-key-constraint-failed-drop-table-users/</link>
        <guid isPermaLink="true">https://www.wazalab.com/2021/08/04/sqlite3%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%a0%e3%82%92%e5%89%8a%e9%99%a4%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95-sqlite3constraintexception-foreign-key-constraint-failed-drop-table-users/</guid>
      </item>
    
      <item>
        <title>wコマンドのParserをrubyで書いた。</title>
        <description>&lt;p&gt;/dev/pts以下にファイルがない時があったのでwコマンドをパースすることにした。（おそらくLXDコンテナ内だからかな）&lt;/p&gt;
&lt;pre class=&quot;theme:sublime-text lang:ruby decode:true &quot;&gt;  def idle_by_w_command
    cmd = &quot;w | grep #{self.username} | awk '{print $5}'&quot;
    output = self._exec(cmd, &quot;admin&quot;)
    output.split(&quot;\n&quot;).map{|line|
      if line =~ /(\d+)days/
        $1.to_i * 3600 * 24
      elsif line =~ /(\d+):(\d+)m$/
        $1.to_i * 3600 + $2.to_i * 60
      elsif line =~ /(\d+):(\d+)$/
        $1.to_i * 60 + $2.to_i 
      elsif line =~ /([0-9]*[.])?[0-9]+s$/
        $1.to_i
      end
    }.compact
  end&lt;/pre&gt;
</description>
        <pubDate>Tue, 03 Aug 2021 14:20:02 +0000</pubDate>
        <link>https://www.wazalab.com/2021/08/03/w%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%81%aeparser%e3%82%92ruby%e3%81%a7%e6%9b%b8%e3%81%84%e3%81%9f%e3%80%82/</link>
        <guid isPermaLink="true">https://www.wazalab.com/2021/08/03/w%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%81%aeparser%e3%82%92ruby%e3%81%a7%e6%9b%b8%e3%81%84%e3%81%9f%e3%80%82/</guid>
      </item>
    
      <item>
        <title>[Javascript] mark tagを使ってテーブル内の文字をハイライトする</title>
        <description>&lt;p&gt;上記画像の緑のフォントのやつです。単純にmarkタグを前後に入れてcssを整えれば完成。&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;pre class=&quot;theme:sublime-text lang:js decode:true &quot;&gt;    highlightKey($('input#q').val())

    function highlightKey(key){
      var valThis = key; 
      $('table').find('tr td').each(function() {
        if ($(this).attr('data-search') !== 'false') {
          var text = $(this).text();
          var textL = text.toLowerCase();
          var position = textL.indexOf(valThis.toLowerCase());

          var regex = new RegExp(valThis, 'ig');
          text = text.replace(regex, (match, $1) =&amp;gt; {
            // Return the replacement
            return '&amp;lt;mark&amp;gt;' + match + '&amp;lt;/mark&amp;gt;';
          });

          $(this).html(text);

          if (position !== -1) {
            setTimeout(function() {
              if ($(this).parent().find('mark').is(':empty')) {
                $('mark').remove();
              }
            }.bind(this), 0);
          } else {
            $(this).text(text);
          }
        }

      });
    }&lt;/pre&gt;
</description>
        <pubDate>Thu, 29 Jul 2021 08:44:20 +0000</pubDate>
        <link>https://www.wazalab.com/2021/07/29/javascript-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e5%86%85%e3%81%ae%e6%96%87%e5%ad%97%e3%82%92%e3%83%8f%e3%82%a4%e3%83%a9%e3%82%a4%e3%83%88%e3%81%99%e3%82%8b/</link>
        <guid isPermaLink="true">https://www.wazalab.com/2021/07/29/javascript-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e5%86%85%e3%81%ae%e6%96%87%e5%ad%97%e3%82%92%e3%83%8f%e3%82%a4%e3%83%a9%e3%82%a4%e3%83%88%e3%81%99%e3%82%8b/</guid>
      </item>
    
      <item>
        <title>Railsで一番シンプルな検索の実装</title>
        <description>&lt;p&gt;数分できたので多分最高にシンプル。&lt;/p&gt;

&lt;p&gt;コントローラにクラスメソッド追加。&lt;/p&gt;
&lt;pre class=&quot;theme:sublime-text lang:ruby decode:true&quot; title=&quot;controller#index&quot;&gt;def index
  @commands = Pipe.search(params[:q]).paginate(page: params[:page])
end&lt;/pre&gt;
&lt;p&gt;モデルにロジック記述。ポイントはCase insensitiveにしているところとOR検索してるところ。&lt;/p&gt;
&lt;pre class=&quot;theme:sublime-text lang:ruby decode:true&quot;&gt;  def self.search(query)
    if query.present?
      q = query.downcase
      Pipe.where('lower(title) LIKE ?', &quot;%#{q}%&quot;).or(Pipe.where('lower(line) LIKE ?', &quot;%#{q}%&quot;))
    else
      Pipe.all
    end
  end&lt;/pre&gt;
&lt;p&gt;Viewはこんな感じ。&lt;/p&gt;
&lt;pre class=&quot;theme:sublime-text lang:ruby decode:true &quot;&gt;&amp;lt;%= form_with(url: '/cmds', method: 'get', local: true) do %&amp;gt;
  &amp;lt;%= text_field_tag(:q, &quot;&quot;, class: &quot;uk-input uk-form-width-medium&quot;) %&amp;gt;
　　&amp;lt;%= submit_tag(&quot;Search&quot;, class: &quot;uk-button uk-button-default&quot;) %&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
</description>
        <pubDate>Tue, 27 Jul 2021 08:43:24 +0000</pubDate>
        <link>https://www.wazalab.com/2021/07/27/rails%e3%81%a7%e4%b8%80%e7%95%aa%e3%82%b7%e3%83%b3%e3%83%97%e3%83%ab%e3%81%aa%e6%a4%9c%e7%b4%a2%e3%81%ae%e5%ae%9f%e8%a3%85/</link>
        <guid isPermaLink="true">https://www.wazalab.com/2021/07/27/rails%e3%81%a7%e4%b8%80%e7%95%aa%e3%82%b7%e3%83%b3%e3%83%97%e3%83%ab%e3%81%aa%e6%a4%9c%e7%b4%a2%e3%81%ae%e5%ae%9f%e8%a3%85/</guid>
      </item>
    
  </channel>
</rss>
