MariaDB: Fix “Can’t read dir of ‘/usr/local/etc/my.cnf.d'” on OSX



Upgrading PHP in Mac OSX Sierra

$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
$ export PATH=/usr/local/php5/bin:$PATH

To select which php version that you want to install, you can see the list on this website https://php-osx.liip.ch/.

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

Reference: http://tooky.co.uk/there-was-a-problem-with-the-editor-vi-git-on-mac-os-x/

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

Reference: http://stackoverflow.com/a/13908492/1936697

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. 😀

Generate Excel File in Django and Write it on Memory

I’m creating report to excel format using XlsxWriter, and here is some trick to generate excel file on memory instead of write the file to disk before we throw it to http response attachment.

import xlsxwriter

    import cStringIO as StringIO
except ImportError:
    import StringIO

from django.http import HttpResponse

def download_view(request):
    # Create file on memory
    output = StringIO.StringIO()

    # Generate excel.
    workbook = xlsxwriter.Workbook(output, {'in_memory': True})
    worksheet = workbook.add_worksheet()
    worksheet.write('A1', 'Hello export.')

    # Construct response.
    response = HttpResponse(output.read(), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    response['Content-Disposition'] = 'attachment; filename=your_file_name.xlsx'
    return response

Reference: http://stackoverflow.com/questions/16393242/xlsxwriter-object-save-as-http-response-to-create-download-in-django