Discourse维护笔记

版本升级

cd /var/discourse
git pull
./launcher rebuild app

磁盘空间清理

每次升级discourse版本,都会build一个新的docker image,下载discourse/base的image,那么进行清理很有必要。

launcher cleanup是discourse内建的一个清理程序,安全且有效

cd /var/discourse
/var/discourse# ./launcher cleanup 

The following command will
- Delete all docker images for old containers
- Delete all stopped and orphan containers

Are you sure (Y/n): Y
Starting Cleanup (bytes free 26462384)
Finished Cleanup (bytes free 37250136)

在清理前,磁盘空间已使用19G

/var/discourse# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   19G   28G  41% /

清理后,腾出来7G的空间,对于小容量的VPS来说,相当可观。这个主要是清理掉了一些无用的docker image

/var/discourse# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   12G   36G  24% /

邮件发送

之前临时使用腾讯的企业邮件来发送discourse邮件,在用户数量略多一点之后,发送就很难成功了。可以使用mailgun代替

My hackintosh build

High Sierra 10.13.5

Components

  • i3 8100
  • ASUS h110m-k d3 MATX board (Add micro code to BIOS, support i3 8100)
  • 8G x 2 DDR3 1600 RAM (For AMD only)
  • Micron 1100 256 GB Solid State Drive
  • Huntkey SUPER 400N 300 Watt SMPS
  • Fenvi FV-T919 BCM94360 WiFi/Bluetooth PCI-E card

The build use integrated graphics Intel UHD 630. The Fenvi FV-T919 card can be driven directly without any changes. I can use my old apple keyboard and trackpad perfectly.

Update BIOS for ASUS motherboard

ASUS h110m-k d3 can’t support i3 8100 directly. But I bought the motherboard from taobao and the seller changed the BIOS to ASRock motherboard already. The motherboard can work with i3 8100 directly but many options are missed for ASUS motherboard T_T

I re-flashed another BIOS file from here. Please note: the default CPU core voltage is too high for i3 8100 in the new BIOS. I change it to 1.040 volt.

BIOS

See the section “Recommended BIOS Settings” at tonymacx86

For iGPU i3 8100, add the bios option

  • Graphics Configuration → DVMT Pre-Allocated : 128MB

The Installation

I followed the Installation Guide at tonymacx86. I used UniBeast to create a bootable High Sierra install on a 16GB USB drive to both format the internal SSD and install macOS.

Options for UniBeast:

  • PCI Devices
    • USB Ownership
    • USB InjectAll

Problem: The USB keyboard and mouse can’t work at the installation screen. I copied the USBInjectAll.kext to /EFI/CLOVER/Kexts/Other and it works again.

Post installation for MultiBeast

  • UEFI Boot mode
  • Drivers > Audio > Realtek ALCxxx > ALC887/888b
  • Drivers > Misc > FakeSMC
  • Drivers > Network > Realtek > RealtekRTL8111 v2.2.2
  • Drivers > USB > Remove XHCI USB port limit
  • Drivers > USB > USBInjectAll
  • Graphics > Intel Graphics Fixup
  • SMBIOS: 17,1

For Intel UHD 630 graphics:

I copied drivers from RehabMan

EFI/CLOVER/Kexts/Other:

  • AppleIntelKBLGraphicsFramebufferInjector_3e9x.kext
  • FakePCIID_Intel_HD_Graphics.kext
  • FakePCIID.kext
  • IntelGraphicsFixup.kext
  • Lilu.kext
  • Shiki.kext

Edit config.plist with Clover Configurator

  • Bootflag: shikigva=1
  • Devices/FakeID/IntelGFX: 0x3E928086
  • Graphics: Inject Intel – Empty ig-platform-id
  • SMBIOS: 17,1

Problem

  • Sleep: Can’t wake from sleep mode

Files

DA14580 advertises to a specify channel

For BLE, Channels 37, 38, and 39 are used only for sending advertisement packets. DA14580 advertises at channel 37, 38 and 39 in the example project from Dialog. But sometimes we need it advertises to a specify channel.

Here are the channel define In the file co_bt.h

///Advertising channels enables
enum adv_channel_map
{
  ///Byte value for advertising channel map for channel 37 enable
  ADV_CHNL_37_EN = 0x01,
  ///Byte value for advertising channel map for channel 38 enable
  ADV_CHNL_38_EN,
  ///Byte value for advertising channel map for channel 39 enable
  ADV_CHNL_39_EN = 0x04,
  ///Byte value for advertising channel map for channel 37, 38 and 39 enable
  ADV_ALL_CHNLS_EN = 0x07,
  ///Enumeration end value for advertising channels enable value check
  ADV_CHNL_END
};

Here’s the code to let DA14580 advertises to channel 37

#define APP_ADV_CHMAP ADV_CHNL_37_EN

....

struct gapm_start_advertise_cmd *cmd;
....
cmd->channel_map = APP_ADV_CHMAP;

Simple script for J-Link RTT viewer

I debug NRF52 chip with JLink real time terminal. It’s pretty to use J-Link RTT viewer on my macOS. For example, I ran this command for open a RTT viewer window.

you@yourcomputer:~$JLinkExe -device nRF52 -speed 4000 -if SWD -autoconnect 1

SEGGER J-Link Commander V5.10u (Compiled Mar 17 2016 19:06:22)
DLL version V5.10u, compiled Mar 17 2016 19:06:19

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Mar 15 2016 18:03:17
Hardware version: V1.00
VTref = 3.300V


Type "connect" to establish a target connection, '?' for help

We can use JLinkRTTClient to check the RTT output. But sometimes JLinkRTTClient will not reconnect if the JLinkExe reopened. A simple script can do this job

while true; do nc localhost 19021; sleep 2; done;

I’ve written this line in my makefile.

如何将git的master分支整个替换为另外一个分支

我有一个git仓库,其中master分支的代码已经落后几个月了,而另外一个blah分支却一直在持续提交。现在想把blah分支更名为master,同时也更新remote上的master。

这个操作似乎并不能用简单的git branch -m来解决。搜索发现也有不少人有类似需求,贴上解决方法。

方法一

如果blah分支能够快速merge到master分支,那么采用这个方法

git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

方法二

如果分支合并时出现了冲突,而你的remote仓库是github或者bitbucket,那么只能强上了

git branch -m master old-master
git branch -m seotweaks master
git push -f origin master

以上,我的情况只适合第二种,强上成功

Arduino的蓝牙4.0串口透明传输模块

最近利用业余时间做了点小玩意

什么是BLUESHIELD?

BlueShield是一块支持蓝牙4.0串口透明传输模块,专为Arduino开发板设计,支持大多数Arduino开发板及衍生版本。

BLUESHIELD能干什么?

可以让你的iOS设备例如iPhone 5, iPhone 4S等等(兼容设备请参考上文)和Arduino通过蓝牙4.0通讯,将数据通过串口透明传输。

我能用它来和ARDUINO, IOS设备做些什么?

  • 通过iPhone传输数据Arduino,完成遥控操作
  • 将传感器信息通过串口传给iPhone以备后续操作
  • Arduino通过iOS设备来访问互联网信息
  • 更多用法,依赖你的想象力..

详细内容见BlueShield发布 — Arduino的蓝牙4.0串口透明传输模块

购买连接

tmux的滚屏

tmux下无法滚屏很烦人。

一句话就解决了: CTRL + B 再按 \”[\”,这时就可以用光标键来操作翻页滚屏

如果需要兼容vim的操作方式,那么在~/.tmux.conf加上一行:

setw -g mode-keys vi

vimari – safari下的vimium扩展

虽说我现在用的主力浏览器还是chrome,但是偶尔还是会给safari一些机会,这让在chrome下用惯了vimium插件的我很不适应,按下熟悉的按钮没得到应有的反馈,简直就跟残废了似的。

于是我开始放狗搜索,然后得到了这个 — vimari.

简单介绍

vimari从chrome的vimium移植而来,大部分代码都是基于vimium。而vimium对于chrome来说,就象是vimperator之于firefox,在浏览网页的时候,也能带来vim类似的操作体验,对于vim控来说实在是不可多得的好扩展。

Vimari is a Safari extension that provides keyboard based navigation. The code is heavily based on \’vimium\’, a chrome extension that provides much more extensive features.
Vimari attempts to provide a lightweight port of vimium to Safari, taking the best components of vimium and adapting them to Safari.

稍加配置,我就很容易获得了和后者类似的使用体验。例如下图的配置选项中,我把 Modifier key to preceed commands 这一项留空,按下f键就可以选择打开页面上的某个链接,而不是使用它默认的快捷键ctrl + f.

\"vimari\"

注意事项

安装扩展之后请即刻升级至最新版本,否则可定制的选项比较少。

多个github帐号的ssh keys支持

不知不觉就有了多个github帐户,平时为了方便都是采用ssh去操作git,所以这个时候问题就来了,在同一台机器上对多个github操作时,会因为ssh key只有一个而无法提交。所以我需要想办法配置多个ssh keys.

解决办法

放狗搜了一圈,有类似需求的大有人在。例如这里:Multiple GitHub Accounts & SSH Config

\’I\’m having some trouble getting two different SSH keys/GitHub accounts to play well together. I have the following setup:

Repos accessible from one account using git@github.com:accountname Repos accessible from another account using git@github.com:anotheraccount

傻瓜操作步骤

生成新的ssh key

ssh-add这一步很重要,否则是前功尽弃


ssh-keygen -t rsa -C \'work@mail.com\'
ssh-add ~/.ssh/work_rsa

配置.ssh/config

我只需要在~/.ssh/config里新增一个Host的别名,将不同帐号的区分开来就可以了。

Host me.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/me_rsa

Host work.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/work_rsa

配置git仓库

需要把git的配置更改过来,其中github.com更换为work.github.com,这样它会找到对应的key来登录。

git remote add origin git@work.github.com:work/test.git

在Git下创建一个空分支

有时候我们需要在Git下创建一个空分支,从头开始Coding —— 这大概是那些重构帝最喜欢的事情。参考了github,才找到一个合适的方法。

怎样安全的进行这项操作

我们需要建一个“孤立”的空分支,为了尽可能的保证数据安全,最好还是重新clone一份代码。

$git clone https://github.com/user/repo.git
# Clone our repo

# Cloning into \'repo\'...
# remote: Counting objects: 2791, done.
# remote: Compressing objects: 100% (1225/1225), done.
# remote: Total 2791 (delta 1722), reused 2513 (delta 1493)
# Receiving objects: 100% (2791/2791), 3.77 MiB | 969 KiB/s, done.
# Resolving deltas: 100% (1722/1722), done.

开工

这里以github的操作为例,下面试图创建一个名为gh-pages的空分支

$cd repo

$ git checkout --orphan gh-pages
# 创建一个orphan的分支,这个分支是独立的
Switched to a new branch \'gh-pages\'

git rm -rf .
# 删除原来代码树下的所有文件
rm \'.gitignore\'

注意这个时候你用git branch命令是看不见当前分支的名字的,除非你进行了第一次commit。

下面我们开始添加一些代码文件,例如这里新增了一个index.html

$ echo \"My GitHub Page\" > index.html
$ git add .
$ git commit -a -m \"First pages commit\"
$ git push origin gh-pages

在commit操作之后,你就可以用git branch命令看到新分支的名字了,然后push到远程仓库。

参考链接