I have a site which sends out emails through my corporate email account (Outlook), here are the steps need to send emails using Django:
Let's say my username is
email@example.com and the password is
123 for my email account.
- Make sure the following settings are in your
- In your code:
That should be it :)
Two special characters are involved here:
- Carriage Return (CR or \r in many programming languages)
- Line Feed (LR or \n)
I never understood what those terms mean until I read that they are inherited from typewriters. When typing on a type writer, two physical actions have to happen in order to continue typing on the next line. First, the carriage needs to return to the very beginning (the far left and makes the ding sound). Then, the typewriter needs to move the page up a little so that we can type on a new line. The moving page up action is called line feed.
CR+LR (i.e. \r\n) to denote a new line but on Unix and Unix-like machines (e.g. Linux), only
LF or \n is used.
I run into a problem today, here is the snippet:
-101 >> 1 is
-110011 instead of
When js stores a negative number, it does the following things:
- get the binary representation of the absolute value of the negative number
- replace 0s with 1s and 1s with 0s
- add 1 to the result of step 2
So in my case -101 >> 1, we first convert -101 to its binary representation:
The binary representation of Math.abs(-101) is:
invert the 0s and 1s:
add 1 to the end:
Now, shift it to the right by 1:
For our example, this means that when logging the result of -101 >> 1, JS will output minus sign + the binary representation of the positive number. But the positive number is not 101 >> 1 because 101 >> 1 gives you:
To get the correct result, we have to reverse the aforementioned step 1-3:
Reverse step 3 by subtracting 1, we get:
Reverse step 2 by invert 0s and 1s:
Reverse step 1 by converting this binary to integer:
Finally, when JS logs the result of -101 >> 1, it should be in the format of minus sign + the binary representation of 51:
I was running a django app on a linux machine and when I tried to login to the admin page, I kept getting redirected to the login page itself. It looks like this:
- POST /login/ 302
- GET / 302 < - should give me a 200 single I have logged in successfully but returns 302 instead
- GET ?next=/ 200 <- back to login page again
The site works when I use
./manage runserver but it wouldn't work when I use gunicorn to run it. I clear the cookie but it didn't work. I tried to set
debug = False didn't work either. Eventially I found the problem, I wanted to use the database to store sessions, so I did this:
For some reason, my session cache is messed up and I have to use this setting instead:
Instead of storing cache in memory which disappears after server restart,
cached_db writes it to the database. I have used the
cache option before and worked but not this time.
I had the pleasure of setting up my own pypi server last week because the server I had to work with is behind a corporate firewall.
To setup your own pypi server, here is what to do:
- Download pypiserver, then:
Config pypyserver settings:
Enter the following info in to
Setup the packages dir, this is the place where you store the packages:
You might want to keep the server running even after you logout of terminal:
You need to stuff your packages folder so that there will be something for
pip install, here are essential packages you need to at least get a virtual environment running:
To download these packages, just go to
https://pypi.python.org/pypi/ and search for the package name, then download the tar.gz version of that package. Once downloaded, move the zip file to the
To verify that the server is up and running， simply go to
localhost:8080/simple/, you should see a list of package names (or empty if you haven't copied any packages into the packages folder yet).
Config your client to download python packages from your server:
Put the following lines into
Done! Try using pip install and it will download a package instantly from your ~/packages folder and install it :)
Found an excellent snippet here by monikkinom, which compresses all uploaded images to jpg before saving to disk:
According to the official doc, the parameters for the
file, field_name, name, content_type, size, charset, content_type_extra=None
If you want to scale the image and still keeps its aspect ratio:
1. Mark an object iterable
To mark an object iterable, you need to add a
Symbol.iterator property to it:
Symbol.iterator part looks really odd if you don't know what
Symbol is all about. One way to think about it is to see it as metadata that describes the hidden behaviors of an object. When an object is marked with the iterator symbol, it means you can loop through it like an array.
2. Return an iterator object
The code snippet above returns an iterator object. An iterator object needs to have a
next method which is a function that returns an iterator result object:
3. Return an iterator result object
Finally, I mean finally we can return some real values rather than wrappers that conforms to the iterable and iterator protocal.The iterator result object has to have two properties, one named
value and the other named
As long as an object has the three traits explained above, it is iterable and can be used in a
for...of loop or being spreaded
Putting it all together
Here is a jsbin link of the code above.
To use ES6 syntax and define an iterator within a class:
The HTTP 1.1 specification states:
A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy.
But many modern browsers supports more than that:
The connection limitation is per hostname not IP address. 
Thus, even a.test.com and b.test.com points to the same ip address, you can still double the number of parrallel connections.
On Ubuntu 14.04, the conifg file for sshd is located at:
Before making any modification, make a copy of the original config and make it read-only:
Then, open up
sshd_config and modify the following lines:
Restart ssh service to make the new config effective:
To limit the number of login attempts during a time period, enable the
Uncomplicated Firewall by:
Then, limit the number of ssh login attempts within 30 seconds to be 10 tries. More attempts will be dropped by issuing this command:
How to config your client
Once the server config has taken effect, you need to update your client ssh config which is found at
~/.ssh/config on your computer.
PubKeyAuthentication and a absolute/relative path to the private_key are added.
I work on a Ubuntu (14.04) machine with Postgres 9.4 installed. The config file directory of Postgres is located at:
Inside the config file, uncomment and adjust the following lines:
These are the basic options I enabled, and to make this new change effective immediately, restart postgres by:
For more config explanation, check the official doc here