Remove unused settings from Rocket.Chat

I was going to add a new setting item - Apps_Game_Center_enabled into the settings page, but some extra unwanted settings were also added to this group. Although, I've already removed these items from the MongoDB. I still saw them in the settings page, it's so weird...

By diving into the codebase, I finally found that we are using PrivateSettingsCachedCollection to cache the settings. With this finding, I solved the issue with the following code:

Inject the following code below

1
2
3
4
...
const rcSettings = settings.collectionPrivate.find({ group: groupId }, { sort: { section: 1, sorter: 1, i18nLabel: 1 } }).fetch();
const sections = {};
...

1
2
3
4
5
6
7
8
9
10
11
12
13
// the code to be injected
rcSettings.forEach(({ _id, section }) => {
const group = 'Apps';
const whitelist = [
'Apps_Framework_enabled',
'Apps_Framework_Development_Mode',
'Apps_Game_Center_enabled',
];

if (section === group && !whitelist.includes(_id)) {
settings.collectionPrivate.remove({ _id });
}
});

Lastly, run meteor shell and .reload to reload the project, you will find the extra settings have be removed from the collection 😆

Something went wrong installing the sharp module

Sometimes, when I switch to a new branch of Rocket.Chat I need to suffer pains from the native modules rebuilding. The sharp module for example, maybe possibly built unsuccessfully.

You will receive an error similar to Something went wrong installing the sharp module. The solution is to run the command meteor npm rebuild to rebuild modules. Hopefully, you can see some detailed errors during the recompiling/building and you can solve it easily.

Bundle ES modules to browser with Browserify

2019-11-12 Update:

We can use gulp to simplify the workflow:

1
2
3
4
5
6
const bundle_sdk = shell.task([
`echo "window.AppsEngineUIClient = require('./AppsEngineUIClient').AppsEngineUIClient;" > client/glue.js`,
'cd client && npx browserify glue.js | npx uglifyjs > AppsEngineUIClient.min.js'
]);

gulp.task('bundle', bundle_sdk);

Below is the original post:

Firstly, install related dependencies with npm:

1
npm i -g browserify uglify-es

Then, create a glue script (here we can name it main.js) to inject the ES module to be a window property.

1
window.AppsEngineUIClient = require('./AppsEngineUIClient').AppsEngineUIClient;

For the last step, use browserify to bundle modules and uglifyjs to minify the script (remove all comments for example).

1
browserify main.js | uglifyjs > AppsEngineUIClient.min.js

Try the docker for the first time

  • 2019-11-9

docker login

Log in to a Docker registry. If no server is specified, the default is defined by the daemon.

-p, --password string

Password

-u, --username string

Username

Example

1
docker login -u lolimay

docker build

build an image from a Dockerfile

-t, --tag list

Name and optionally a tag in the 'name:tag' format. If the tag is not specified, use latest by default.

Example

1
docker build -t lolimay/cheers2019:test .

docker run

Run a command in a new container

-i, --interactive

Keep STDIN open even if not attached

-t, --tty

Allocate a pseudo-TTY

--rm

Automatically remove the container when it exits

Example

1
docker run -it --rm lolimay/cheers2019:test

docker push

Push an image or a repository to a registry

Example

1
docker push lolimay/cheers2019

Install proxychains4 on your mac

1
2
3
4
5
6
7
8
git clone https://github.com/rofl0r/proxychains-ng
cd proxychains-ng
./configure --prefix=/usr \
--sysconfdir=/etc \
--bindir=/usr/local/bin \
--libdir=/usr/local/lib \
make && make install
sudo make install-config # install the config file

The try sudo vim /etc/proxychains.conf to personalise your proxy configuration.

Unexpected end of JSON input while parsing...

I am going to fix vulnerabilities by run the command npm audit fix but meet an error:

1
2
3
4
npm ERR! Unexpected end of JSON input while parsing near '...g/backbone/-/backbone'

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lolimay/.npm/_logs/2019-11-06T17_40_28_140Z-debug.log

It's was so frustrated because I have no idea how to solve the problem. The only way for me is to google it.

Then I found a feasible solution:

1
npm cache clean --force

After cleaning the npm's cache, everything goes well. The nice day comes back 😄

Delete branches by patterns in Git

1
2
# delete all branches that startswith bump.
git branch | grep "bump.*" | xargs git branch -D

We can also use git fetch to copy a remote branch to local:

1
git fetch origin move-host-logic:move-host-logic

Reference: Deleting Multiple Branches in Git

Checkout GitHub pull requests locally

  • 2019-11-6
1
git fetch origin pull/ID/head:BRANCHNAME

Reference: Checking out pull requests locally - GitHub Help

Print formatted tuple in Python

As we know, we can print formatted JSON string with the following JavaScript code:

1
console.log(JSON.stringify(object, null, 4)); // indent 4 spaces

In Python, we can do the same thing with ffprint, which is a built-in module of Python.

Talk is cheap, show me the code 😜

1
2
3
4
5
6
7
8
import yaml
from pprint import pprint

with open('../config.yml') as stream:
try:
pprint(yaml.safe_load(stream))
except yaml.YAMLError as ex:
print(ex)

Result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{'batch_size': 8,
'bbox_output': True,
'bbox_output_path': 'tracking_result',
'context_amount': 0.5,
'examplar_size': 127,
'gamma': 0.8685,
'instance_size': 255,
'label_weight_method': 'balanced',
'lr': 0.01,
'momentum': 0.9,
'net': 'SiamFC_50_model.pth',
'net_base_path': '/Train/model',
'num_epoch': 50,
'num_pairs': 53200,
'num_scale': 3,
'pos_pair_range': 100,
'rNeg': 0,
'rPos': 16,
'response_UP': 16,
'scale_LR': 0.59,
'scale_max': 5,
'scale_min': 0.2,
'scale_penalty': 0.9745,
'scale_step': 1.0375,
'score_size': 17,
'seq_base_path': '/computervision/datasets/OTB100',
'step_size': 1,
'stride': 8,
'sub_mean': 0,
'train_num_workers': 12,
'val_num_workers': 8,
'val_ratio': 0.1,
'video': 'Lemming',
'visualization': False,
'w_influence': 0.176,
'weight_decay': 0.0005,
'windowing': 'cosine'}

List all branches of one remote repository

We can use git remote --all to show all branches from the remote and the local.

But if we only want to show branches of a specific remote repo?

git ls-remote <remote> can make your day happy 😜