How to post code into wordpress post by email feature

I just had to do some manual experimentation to do this.So far the only way is to use [ sourcecode ] (without spaces).

You can’t specify a language since those get escaped automagically.

If anyone has better ideas for a wordpress hosted site (not self hosted), please let me know!

class ExampleSource():
pass

nginx: [emerg] invalid number of arguments in “return” directive

I was using a 4 year old installation of nginx (0.7) – apt-get update, apt-get install nginx claimed I had the latest version…

Turns out this error means the return directive isn’t supported in the `return 301 foo.com` format until a later nginx.

Install the latest nginx by following the docs at http://wiki.nginx.org/Install

sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update 
apt-get install nginx

Django Admin Site Namespace Reverse URLS

I was having an odd issue where {% url ‘custom_admin:foo_bar_changelist’ %} would work from one admin but not another location. I put it on Stack Overflow… got an answer that one can manually construct the adminsite include via include(adminsite.get_urls(), ‘app_name’, ‘namespace’).

http://stackoverflow.com/questions/17706548/django-multiple-adminsite-noreversematch-from-second-adminsite-instance/17707090?noredirect=1#comment25845627_17707090

Shopify API SSL Requirement

Got an error suddenly starting in the past 2 days (2013) that my API connection failed due to “SSL Required”.

{"errors":"SSL required"}

This exact error means you need to use HTTPS in your api requests.

Broke at a critical time for us.

DataTables – fnFilter match blank space regexp

Wow, I had to dig into the source of DataTables 1.9.3 to figure out why a regular expression with no “smart filter” was failing.

Turns out each column is returning massively padded data due to the HTML blocks containing spaces.

Trim it to match regexps that rely on position like ^$ (blank) or .+ (1+). Those extra leading/trailing whitespace chars are the problem.

Go to the DataTables source… look at this function and trim whitespace from sData:

Note that there may be an API for overriding internal functions… but I can’t be bothered to look right now. This has been a long debug.

		 */
		function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart, bCaseInsensitive )
		{
			if ( sInput === "" )
			{
				return;
			}
			
			var iIndexCorrector = 0;
			var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
			for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
			{
				var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
					oSettings.aoColumns[iColumn].sType );
				if ( ! rpSearch.test( sData.trim() ) ) ////////// add .trim() here

Django — Prevent ModelForm from updating values if user did not submit them

I have a model that is being shared across many different forms. An ugly side effect of this was that if I ever forgot to ensure that the HTML rendered contained *exactly* the fields defined in the form, django would overwrite the values.

Here’s a mixin that you can add to any ModelForm which will only update values.

Note that this still allows users to update a model field explicitly with a blank.

from django.forms.models import model_to_dict
from django import forms
 
 
class OverwriteOnlyModelFormMixin(object):
    '''
    Delete POST keys that were not actually found in the POST dict
    to prevent accidental overwriting of fields due to missing POST data.
    '''
    def clean(self):
        cleaned_data = super(OverwriteOnlyModelFormMixin, self).clean()
 
        for field in cleaned_data.keys():
            if self.prefix is not None:
                post_key = '-'.join((self.prefix, field))
            else:
                post_key = field
 
            if post_key not in self.data:
                # value was not posted, thus it should not overwrite any data.
                del cleaned_data[field]
 
        # only overwrite keys that were actually submitted via POST.
        model_data = model_to_dict(self.instance)
        model_data.update(cleaned_data)
        return model_data

Increase upload size on WordPress DreamHost

This is stupid.

All htaccess, php.ini, define_ methods failed.

This is what works:

Download this
http://sxi.sabrextreme.com/phpini

Put it on your server.

Go to it with your browser.

Click install.

Navigate to the mywordpress.com/cgi-bin folder and edit php.ini

Find max_upload_size and modify to whatever you want.
find max_post_size and modify to whatever you want.

This is stupid.