Today I will tell you about the massive success that is whypy3.com. With hundreds of users a day (on the best day when it reached page two of Hacker News and hundreds actually being 103), it has been a tremendous success in the lucrative Python code snippet market. By presenting small snippets of code displaying cool features of Python 3, I was able to single–handedly convert millions (1e-6 millions to be exact) of Python 2 users to true Python 3 believers.
It all started when I saw a tweet about a cool Python 3 feature I haven’t seen before. This amazing feature automatically resolves any exception in your code by suppressing it. Who needs pesky exceptions anyway? Alternatively, you can use it to cleanly ignore expected exceptions instead of the usual
from contextlib import suppress
There are obviously way better and bigger reasons to finally make that move to Python 3. But what if you can be lured in by some cool cheap tricks? And that’s exactly why I created whypy3.com. It’s a tool that us Python 3 lovers can use to try and slowly wear down on an insistent boss or colleague. It’s also a fun way for me to share all my favorite Python 3 features so I don’t forget them.
I was initially going to to do the usual static S3 website with CloudFront/CloudFlare. But I also wanted it to be easy for other people to contribute snippets. The obvious choice was GitHub, and since I’m already using GitHub, why not give GitHub Pages a try? Getting it up and running was a breeze. To make it easier to contribute without editing HTML, I decided to use the full blown Jekyll setup. I had to fight a little bit with Jekyll to get highlighting working, but overall it took no time to get a solid looking site up and running.
After posting to Hacker News, I even got a few pull requests for more snippets. To this day, I still get some Twitter interactions here and there. I don’t expect this to become a huge project with actual millions of users, but at the end of the day this was pretty fun, I learned some new technologies, and I probably convinced someone to at least start thinking about moving to Python 3.
Do you use Python 3? Please share your favorite feature!
Django 1.10 added a new style of middleware with a different interface and a new setting called
MIDDLWARE instead of
MIDDLEWARE_CLASSES. Creating a class that supports both is easy enough with MiddlewareMixin, but that only works with Django 1.10 and above. What if you want to create middleware that can work with all versions of Django so it can be easily shared?
Writing a compatible middleware is not too hard. The trick is having a fallback for when the import fails on any earlier versions of Django. I couldn’t find a full example anywhere and it took me a few attempts to get it just right, so I thought I’d share my results to save you some time.
from django.core.exceptions import MiddlewareNotUsed
from django.shortcuts import redirect
from django.utils.deprecation import MiddlewareMixin
MiddlewareMixin = object
def __init__(self, *args, **kwargs):
raise MiddlewareNotUsed('DISABLE_MIDDLEWARE is set')
super(CompatibleMiddleware, self).__init__(*args, **kwargs)
def process_request(self, request):
if request.path == '/':
def process_response(self, request, response):
CompatibleMiddleware can now be used in both
MIDDLEWARE_CLASSES. It should also work with any version of Django so it’s easier to share.
I have seen a few “staying safe online” guides lately. I wrote one of my own a while back after some of my friends were threatened online and got worried. This guide should be a good starting point for most common casual internet users. It’s important to remember that no matter what you do if it’s online, it can be hacked.
- Never reuse passwords
- Some websites are easier to hack than others
- Hackers will try the same password on other websites
- Use 1Password for easier management
- Don’t use simple passwords
- Hackers guess passwords all the time
- There are easy automatic tools that enumerate all password options
- Don’t use your name, birthday, SSN, or any public information in passwords
- Keep your computer & phone up-to-date
- Old software has known and easily exploitable vulnerabilities
- Never click links in emails
- Clicking the wrong link can give control of your accounts to hackers
- Manually browse to the website even if the email looks legit
- Always logout on public computers
- Preferably never login on public computers in the first place
- Data can be linger even after logging out
- Some public computers record your passwords
- If it was put online, it will stay online
- Any private information shared can help hacking
- Your name and birth year can be enough to guess your SSN
- Click the little lock icon on top and follow instructions
- Set everything to private
- Hide your birth year
- Click the little triangle on the top right and choose Settings
- Enable login alerts to be notified of hacks
- Enable login approvals
- Enable trusted contacts in case your account is hacked
Securing Google Account
- Enable 2 factor authentication
- Check Google+ privacy
I don’t know why or how, but Google seems to think my little blog is worth something. Terms like “quake flag”, “triple double u”, “the green wire” , “atomic codes” and even “mr. angry pants” return some of my posts in the top 10 results and sometimes even as the first result. NSIS seems to share the same glory with terms like “java runtime download”, “strstr”, “exch”, “createmutex”, “iis version”, “messagebox”, “steam account” and even “windows critical update”. This Google love is very nice and helpful for NSIS but it doesn’t get too much of my attention span when it comes to this blog. People searching for my name or nickname find it as the first result and that’s good enough for me.
However, out of pure curiosity, I’ve decided to perform a little Google experiment. Searching for “kichik” results in my blog and some pages concerning a beautiful actress named Lorena Kichik. Her profile states she’s latin or middle eastern, so I’m not so sure how she ended up with Hungarian or Pakistani last name, but that’s another story. I’m not exactly sure what I’m going to figure out here, but I wanted to know what happens if I directly mention her in my blog. Will this post show up when searching for her name? Will it show when searching for mine? Which would come first – my post or her Facebook or IMDB profile?
Let the games begin!