Posts

Showing posts from August, 2015

Quote of the day

“If a man has lost a leg or an eye, he knows he has lost a leg or an eye; but if he has lost a self—himself—he cannot know it, because he is no longer there to know it.” ~Oliver Sacks, The Man Who Mistook His Wife for a Hat and Other Clinical Tales.

The three best things in life are...

... friendship, sex and reading, and the best of the three is reading. ~Suggested by Michel de Montaigne .

Delete all pending/spam/trash comments from WordPress (Single or Multisite) using WP-CLI

I just wrote this bash shell script to delete all pending/spam/trash comments from WordPress (Single or Multisite) using WP-CLI: Put the script inside your WordPress root and run: $ ./clean_comments.sh These are available statuses of a comment: approve : approved comments hold : pending comments spam : spams trash : comments in the trash bin This is pretty neat huh?!

How to remove leading and trailing spaces in bash

To remove both leading and trailing spaces of a string in bash shell, you can do like following: mytext=' This is a test ' trimed_text="$(echo -e "${mytext}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"

WordPress - How to migrate media (attachment, gallery) properly (single or multisite)

One of the big problem when you migrate your WordPress blog to another server with a new domain name is the media gallery. What happened to me was even though I had already moved all the photos (media) to the new location but nothing showed up in the Media dashboard and all the gallery shortcode in posts were broken. I figured out earlier today that I need to update the media links or attachments attribute when I importing the old data (exported WXR file). Here is the step-by-step detail: (I'm doing this for my multisite WordPress) 1. In the old WordPress: Export old blog data (Tools > Export > select All Content > press Download Export File). You will have a xml file. 2. Copy over all the photos from the old WordPress to the new one. For example: Old: /var/www/oldblog/wp-content/blogs.dir/777/ New: /var/www/newblog/wp-content/uploads/sites/777/ 3. Open the export file using a text editor. Search and replace the old media path with the new one. For example: Ol...

Django - object has no attribute 'user' error

I got this error this morning when trying to test my Django app: Internal Server Error: /staff/acts/email/ Traceback (most recent call last):   File "/path/to/virtualenv/myenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response     response = wrapped_callback(request, *callback_args, **callback_kwargs)   File "/path/to/virtualenv/myenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view     return view_func(request, *args, **kwargs)   File "/path/to/app/views.py", line 519, in email_main     confirm_sent = send_email(confirm_email_form, 'confirm', request)   File "/path/to/virtualenv/myenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view     if test_func(request.user): AttributeError: 'EmailTemplateForm' object has no attribute 'user' I figured out the reason causing this issue is...

Problem with iframes in iOS devices

iframes in iOS devices behave a little bit strange as you all knew. The content displays outside of the iframe. There are many way to fix that issue, here is a quick one: Just replace the iframe tag with  embed and everything will be fine. <embed src="..." type="text/html" ...></embed> Reference: http://stackoverflow.com/questions/10528760/iframe-content-is-displaying-outside-the-iframe-on-ios

Excel to list of dictionaries in Python

This is a pretty neat python snippet I wrote to read an Excel (xlsx) file and convert its data into a list of dictionaries: Note: you need to install the openpyxl module before you can use the snippet $ sudo pip install openpyxl So, you can use the snippet as following: >> from excel_utils import excel_to_dict >> data = excel_to_dict('/path/to/excel/file.xlsx', ['col1', 'col2', 'col3']) >> data[0] {'col1': u'Genius',  'col2': u'Super',  'col3': u'Awesome'} Cool huh? Reference:   https://automatetheboringstuff.com/chapter12/

How to see Windows Product Key in Windows 7 (tested)

To see your Windows 7 machine's product key you can run this script (as an Administrator): Quite handy huh?

How to set course format for multiple courses in Moodle

It's pretty cool using MOOSH command line tool of Moodle. You can set course format to topics for multiple cources in Moodle by running this command: moosh course-config-set category 7 format topics Just awesome!!! Reference: http://moosh-online.com/commands/