在macOS下安装aria2并自动启动RPC

什么是Aria2?

Aria2 is a lightweight download software with Multi-Connection support. Besides HTTP(s) and FTP, it also supports BitTorrent and Metalink.

安装Aria2

最简单的方法是采用homebrew安装aria2

brew install aria2

配置RPC自启动

  • 新增文件并编辑 /usr/local/opt/aria2/homebrew.mxcl.aria2.plist, 内容如下
<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
    <dict>
<key>Label</key>
<string>homebrew.mxcl.aria2</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/aria2/bin/aria2c</string>
<string>--enable-rpc=true</string>
<string>--rpc-secret=yoursecret</string>
<string>--rpc-allow-origin-all=true</string>
<string>--rpc-listen-all=true</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
  • 然后用homebrew启动这个service,默认端口是6800
brew services start aria2

About ESP8266 module

How to detect the flash size of ESP8266 module?

  • Install latest esptool from GitHub or with pip
  • Wire ESP8266 module with a programmer
  • Run command
esptool.py flash_id

You should get some information about the flash of ESP8266 module

esptool.py v2.6-beta1
Found 2 serial ports
Serial port /dev/cu.SLAB_USBtoUART
Connecting........_
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: 18:fe:34:9f:5a:0a
Uploading stub...
Running stub...
Stub running...
Manufacturer: c8
Device: 4013
Detected flash size: 512KB
Hard resetting via RTS pin...
  • So the flash size is 512KB

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

Update From 10.13.6 To 10.14.0

  • Install latest Lilu.kext and WhatEverGreen.kext
  • Install Multibeast 11 (not available yet)
  • Remove:
    • FakePCIID_Intel_HD_Graphics.kext
    • AppleIntelKBLGraphicsFramebufferInjector_3e9x.kext
    • IntelGraphicsFixup.kext
    • Shiki.kext
    • Bootflag: shikigva=1
    • Devices/FakeID/IntelGFX: 0x3E928086
  • Install Mojave from App Store
  • Follow the link Mojave AppleHDA Audio to remove old realtekALC and install AppleALC

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

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

使用CocoaPods时开启inhibit_warnings参数的小问题

inhibit_warnings参数能够有效的抑制CocoaPods引入的第三方代码库产生的warning,但是有时候会产生意想不到的错误,例如我今天引入ReactiveCocoa的时候就产生了下面的错误:

CompileDTraceScript ReactiveCocoa/ReactiveCocoaFramework/ReactiveCocoa/RACSignalProvider.d
    cd /Users/Tony/Code/TestApp/Pods
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/Tony/.rvm/gems/ruby-1.9.3-p194/bin:/Users/Tony/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/Tony/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/Tony/.rvm/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/heroku/bin:/usr/local/git/bin:/usr/local/share/npm/bin:/Applications/MAMP/Library/bin:/Users/Tony/Applications/play:/Users/Tony/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/git/bin:/usr/local/sbin:/Users/Tony/.rvm/bin:/Users/Tony/.ec2/bin"
    /usr/sbin/dtrace -h -DOS_OBJECT_USE_OBJC=0 -fobjc-arc -DOS_OBJECT_USE_OBJC=0 -w -Xanalyzer -analyzer-disable-checker -s ReactiveCocoa/ReactiveCocoaFramework/ReactiveCocoa/RACSignalProvider.d -o /Users/Tony/Library/Developer/Xcode/DerivedData/TestApp-bfkcwbnhjkdedddkxicxplyvlnxq/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-ReactiveCocoa.build/DerivedSources/RACSignalProvider.h

......

Command /usr/sbin/dtrace failed with exit code 2


而我的pod文件中引入方式如下:


pod 'ReactiveCocoa', '~> 2.1', :inhibit_warnings => true

在这里,关闭了inhibit_warnings之后,就可以正常编译了。同理,inhibit_all_warnings也会产生类似的问题。

所以,要开启这个参数,需要谨慎,不要因为一些小小洁癖耽误自己大量的时间。

iBeacons

iBeacons是iOS7的新增的功能,可用于室内近场定位。iOS设备可以检测到附近的iBeacons兼容设备,在当前版本中甚至可以在应用后台运行的情况下获得回调。

iBeacons设备往往都是低功耗的,用Bluetooth Low Energy低功耗蓝牙实现,设计良好的iBeacons设备在一节CR2032纽扣电池支持下应能支持一年以上的使用时间。

iBeacons还有一个有用的特性是可以距离感应,当你的iOS设备检测到了一个iBeacons设备,那么app即可通过CoreLocation监测设备的距离,通过回调的形式通知距离变化。

i

常见应用场景

可以有不少有趣的应用场景,随便列举一些。

  • 商场购物时,靠近某些商品时,提示用户正在打折,或者查看商品的具体信息以及评价。靠近交费区域时,使用某一信用卡支付可以获得优惠。
  • 室内导航,例如机场登机口指示
  • 各种大会入场checkin,免去繁琐的签到流程
  • 各种展览场所,当用户靠近某些展品时,就可以获得相应的介绍信息

什么时候应该使用iBeacons

  • 同时需要检测多个区域
  • 被检测区域可以是一个移动的区域,例如汽车,列车。。
  • 检测区域范围有限的情况(一般不会大于100m)
  • 每个区域需要一些标识做区分的情况
  • 每个区域可以在室内,同一建筑物内,可以有重合
  • 用户愿意开启低功耗蓝牙来检测区域

如何把iOS设备变成一个iBeacon

所有支持低功耗蓝牙技术的iOS设备都可以变成一个iBeacon设备,被其它iOS设备检测到。例如iPhone 4s, iPod Touch5, iPad3及之后的设备,都支持低功耗蓝牙技术。

定义你的iBeacon

首先需要了解4个属性

  • proximity UUID , 是一个iBeacon或一组iBeacons设备的唯一标识,标明它的类型,你可以用osx下的 uuidgen
    命令生成
  • 一个内部identifier ,你在app中自定义的标识
  • 一个 major identifier, 可用于区分一组拥有相同proximity UUID的设备
  • 一个 minor identifier, 可用于区分一组拥有相同proximity UUID和相同major identifier的设备

创建并广播一个iBeacon区域

首先需要定义一个CLBeaconRegion来实现iBeacon,如下

NSUUID *myProximityUUID = [[NSUUID alloc]
    initWithUUIDString:@"566C5595-6EC7-4F08-909F-C954BDCA6CD3"];
NSNumber *branchNumber = @42;
NSNumber *tillNumber = @3;
CLBeaconRegion *region = [[CLBeaconRegion alloc]
    initWithProximityUUID:myProximityUUID
    major:[branchNumber unsignedShortValue]
    minor:[tillNumber unsignedShortValue]
    identifier:@"com.mycompany.store"];

然后把这些信息交由CBPeripheralManager进行广播


NSDictionary *peripheralData =
    [region peripheralDataWithMeasuredPower:nil];
CBPeripheralManager *myPeripheralManager =
    [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
[myPeripheralManager startAdvertising:peripheralData];

于是一个iOS设备就变成了一个iBeacon了

兼容的iBeacon设备

目前Apple并未公布iBeacons的具体技术细节,但是仍然有不少第三方通过蓝牙嗅探工具反向工程实现了iBeacons兼容设备。在国外已经有一些成品上市,例如

  • estimote
  • sticknfind
  • paypal,它甚至将iBeacons融入了它的支付技术

本人也利用TI公司的CC2541实现了一个简单的iBeacons兼容模块,为了未来可能的变化,做了预留的空中升级接口,现在某宝尝试性的对外出售,适用于有一定电子技术动手能力的爱好者测试。

参考链接

使用xctool自动打包,测试xcode项目

xctool是facebook开源的一个命令行工具,用来替代苹果的xcodebuild工具。

功能如下:

  • 像xcode一样跑测试用例
  • 结构化输出编译测试结果
  • 彩色且方便阅读的编译内容输出

示例截图:

xctool

如何安装xctool

最简单的办法是通过homebrew安装xctool

brew update
brew install xctool

搞定

如何使用xctool

打包


path/to/xctool.sh 
  -workspace YourWorkspace.xcworkspace 
  -scheme YourScheme 
  archive

build

path/to/xctool.sh 
  -workspace YourWorkspace.xcworkspace 
  -scheme YourScheme 
  build

测试

path/to/xctool.sh 
  -workspace YourWorkspace.xcworkspace 
  -scheme YourScheme 
  test