Line by Line Simple but Usable VIM Config

🔖 code 

VIM is a great editor, but it’s defaults are a little lacking. Fortunately it’s also extremely configurable. This leads many people (myself included), to scour the internet for lines of internet wisdom to copy in paste into their .vimrc files until they get something that works for them. Before you know it you have 300 lines of unintelligible gobblegook. In this post, (which I’ve started writing in vanilla vim) I’m going to go line by line through individual config items to construct a simple but usable .vimrc without too much magic or frills.

Read more...

GNOME Notifications for Remote Weechat

🔖 code 

I ❤ Weechat. It’s my IRC client of choice. But I also use it for gtalk and Slack. All my conversations in one convenient interface. Even better, I run it in a remote tmux session so I can pick up wherever I left off from anywhere.

The only annoying thing about this setup was the lack of real notifications for private messages or mentions. So I wrote Weelisten.

2017-07-27-gnome-notifications-for-remote-weechat.markdown

Weelisten is a small python script that leverages Weechat’s relay protocol, python 3 asyncio and libnotify so I can get awesome native notifications on my desktop.

Sounds useful? Get it on Github

Throttling Specific Actions in Django Rest Framework Viewsets

🔖 code 

If you are using rate limiting with Django Rest Framework you probably already know that it provides some pretty simple methods for setting global rate limits using DEFAULT_THROTTLE_RATES. You can also set rate limits for specific views using the throttle_classes property on class-based views or the @throttle_classes decorator for function based views.

What if you are using ViewSets but want different throttling rules to apply to different actions? Unfortunately DRF provides no official method of doing this. Luckily we can accomplish this functionality without too much fuss using get_throttles().

Read more...

Dockerize! Lest you forget

🔖 code 

2017-02-26-dockerize!-lest-you-forget.markdown

I host quite a few sideprojects on my VPS. They range from static Jekyll sites (like this one) to large web applications. There’s even some wordpress hiding in a corner, disgraced and neglected.

Despite the fact that none of these sites are actually useful for anything, they still need some poor bastard to keep then running. Over the years I’ve collected quite the assortment of nginx, uwsgi, php, apache, supervisor, and other configs. All of them written at various levels of understanding, none of them tracked anywhere, all of them confusing and terrible.

Read more...

Preserve GET parameters using django-bootstrap3 pagination

🔖 code 

This one got me for a bit. If you are using django-bootstrap3 and also want to use it’s handy bootstrap_pagination template tag for generating pagination links, you may be in for an unplesant surprise if your view uses any GET parameters. While the django-bootstrap-pagination project handles this by default, django-bootstrap3 will not persist GET paramters between pages.

The key to using the bootstrap_pagination tag is the extra argument, which takes a string and appends it to each page. If you have the request_context context processor installed, you can pass in this string using the QueryDict urlencode() method. For example:

{% bootstrap_pagination page_obj extra=request.GET.urlencode %}

Voila. Pagination in django with bootstrap working as it should.

Now You Too Can Become A Syntax Tyrant

🔖 code 

So I really like code linters. My coworkers know this. Actually, I got called a syntax Nazi today by a fellow developer. I’m OK with that. I believe in readability and consistency.

In my projects I make it impossible to make a git commit before the source code passes a flake8 check. How to perform this minor miracle you ask? With a simple git pre-commit hook:

myproject/.git/hooks/pre-commit

#!/bin/sh
flake8 .

When I commit, the hook executes. Since git knows a return of anything besides 0 means abort, it stops the commit from happening. Awesome.

Here is a terminal recording of it in action:

Don’t forget to make your pre-commit hook file executable!

Sane Django Development with Docker

🔖 code 

Recently I started a new Django project, and this time I decided to go all in on Docker. No virtualenvs, no local databases - containers all the way.

There are about a million and ten articles about how to dockerize webapps by now. However, none of them seem to address one simple fact: we don’t simply want to dockerize our applications, we want to develop them too!

sane-django-docker contains a sample django project webapp as well as the necessary config files to run both a development and production server.

Read more...

Upgrading Wheezy to Jessie: Nginx and PHP5-fpm

🔖 code 
I just upgraded this VPS from Debian Wheezy to Jessie. The upgrade went pretty flawless, excpet some minor issues with postgres and the new bad systemd smell. However, if you are running NGINX + PHP5-fpm, you may want to read the news that gets displayed during the upgrade: nginx shipped a modified `fastcgi_params`, which declared `SCRIPT_FILENAME` fastcgi_param. This line has now been removed. From now on we are also shipping fastcgi. Read more...

100 Observations Logged on AstroChallenge!

🔖 featured  astrochallenge  astronomy  code 
I created AstroChallenge to scratch my own itch: to have a place to keep an observation journal for astronomy and to share it with the rest of the community. In that I believe I’ve succeeded, check out my profile and journal. Since then the word has gotten out and other astronomers have been logging their own observations. Now, only 2 weeks after making AstroChallenge public, over 100 observations have been logged! Read more...