SCP from Linux to Windows

This is the scp command that copies a file from Linux to Windows:

scp -C -P {port} {file path on linux} USERNAME@IPADDRESS:mydir\\mysubdir\\filename

The trick is to use \\ in the Windows path. The flag -C compresses the file.

 

Advertisements

Fixing Hg Mistakes

Removing Pushes from Other Branches

I often create a branch by cloning. I do more involved or experimental things in the clone. While the parent branch is available to make small minor updates. As code in the branch progresses, I do commits. And every once in a while, by accident, I do a commit and push. This puts the experimental code in the main branch before its ready. To remove the pushed change set, cd into main and do:

hg strip -r REV

					

Django HTTP 404 Not Found Error

So you’ve got everything working on the Django dev server. Almost everything is working on the staging server… except one URL that sometimes fails with an HTTP 404 Not Found error. What is going on here?

More details; it happens to be a Django form page. The page loads with a problem. The problem occurs after you submit the form. The URL that causes the 404 error is the URL of the form. What is going on here?

In my case, the form_valid() was doing a lot of processing of the form data and the server was timing out. Maybe part of the reason I did not catch this earlier is my dev server is much faster than the Digital Ocean droplet I was using.

Python Dates and Times Cheatsheet

Python (2.7) datetimes are a little frustrating because there are many ways to do each manipulation and there are many applicable 3rd party libraries. Below are code snippets that I think show the best solution. While I appreciate the concept of minimizing dependencies, there are some 3rd party libraries that are so useful, that I just include them as requirements on all my projects.

Aware UTC Now


import datetime

import pytz

now = pytz.utc.localize(datetime.datetime.utcnow())

Aware Now in Timezone

The code below will create an aware time in US/Pacific time regardless of the time zone the machine is running in.


import datetime

import pytz

now = datetime.datetime.now(pytz.timezone('US/Pacific'))

Select2 vs Chosen

Select2 and Chosen are both great javascript widgets for enhancing the HTML select tag. They have a lot of similarity and a few differences. How to pick? These just a few issues I have run into. I am using Select2 V4 and Chosen 1.1.

Form Tabbing

A lot of users prefer keyboard to a mouse. Both widgets allow that. However, Chosen handles tab better. With Chosen, tab completes the entry and moves to the next form field. With Select2, I could not get tab to move to the next field. Select2 messes with the tabindex property. I am guessing that is part of the problem.

Tagging

This is the reason I used Select2 instead of Chosen. Tagging allows the user to input something that is not already in the select widget.

 

 

Django and Memcached: Set Value Not Working

I had a strange memcached bug while using Django. Sometime cache.set(key, value) would save the value. Other times it would not. No warnings or errors. Just not saved.

It turns out the item I was trying to save was near the item size limit of memcached. The default is 1 MB (see the -I flag). Sometimes the item would be less than the max and set would work. Other times it would exceed the limit and set would just stop working.

The man page recommends not exceeding the default. So I solved the problem by saving the item in two parts.

I should also mention that Django file-based cache is pretty easy to use and does not have this limitation. Since all my Django sites run on SSD drives, file-based cache is almost as fast as memcached.