Compiling Proto File

I always forgot how to compile proto file and here is how compile .proto file for my personal note. 😀

$ protoc -I proto_dir/ proto_dir/proto_file.proto --go_out=plugins=grpc:proto

Example above for golang implementation, another programming language can use another out parameter.

  --cpp_out=OUT_DIR           Generate C++ header and source.
  --csharp_out=OUT_DIR        Generate C# source file.
  --java_out=OUT_DIR          Generate Java source file.
  --js_out=OUT_DIR            Generate JavaScript source.
  --objc_out=OUT_DIR          Generate Objective C header and source.
  --php_out=OUT_DIR           Generate PHP source file.
  --python_out=OUT_DIR        Generate Python source file.

Git: Fixing “error: There was a problem with the editor ‘vi’.”

I just installing vim on my machine, but it affected to my installed git. Every I merge my working branch, I always got this error.

error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.

After that, I have to commit manually to the merged changes.

$ git commit "merge from ... to ..."

The error because git using “vi” as the editor and I installed “vim” in my machine.
Here is how to fix this.

$ which vim
$ git config --global core.editor /usr/local/bin/vim


Grep: Find File by Content Keyword

Here is how to use grep to find file by content keywords recursively.

# Find in current directory.
$ grep -nr 'keyword' .

# Find in particular directory.
$ grep -nr 'keyword' target/directory

# Find in particular directory and file extension.
$ grep -nr 'keyword' target/directory --include=*.html


Save Media Files to Local Disk on Django-Storages

I’m using django-storages for storing my media files such us images, or document files to amazon S3. But if we using django-storages, by default all media files will uploaded to remote storage, in my case I’m using amazon S3.

I’m writing simple script to save both on remote and also local disk. To use this class, you just need to subclass this mixin class. Keep in mind to pay attention with mixin class order.

Currently only support save to local disk, but not supported yet to remove local file if the instance removed. Don’t hesitate to fork or improve my code. 😀