Skip to content

Instantly share code, notes, and snippets.

View turtlemonvh's full-sized avatar

Timothy turtlemonvh

View GitHub Profile
@turtlemonvh
turtlemonvh / fix_bad_mysql_restart.py
Created February 21, 2014 17:21
Register this as a crontab to run every hour to check if mysql had a hard time restarting. If so, it may be because this was brought down quickly. Use `sudo crontab -e` when creating the crontab because it needs to run as root to be able to move the pid files and restart the service.
#!/usr/bin/env python
import os
import subprocess
child = subprocess.Popen('service mysqld status', shell=True, stdout=subprocess.PIPE)
# Capture output string
outstr = ''
while True:
@turtlemonvh
turtlemonvh / myapp.conf
Created June 25, 2014 20:05
Apache conf for multiple djangos at subdomains
# Some tips:
# - tips on multiple versions: http://stackoverflow.com/questions/1553165/multiple-django-sites-with-apache-mod-wsgi
# - using the wsgi daemon mode allows better performance with multi-threading
WSGISocketPrefix /var/run/wsgi
Alias /err/ "/var/www/error/"
ErrorDocument 404 /err/HTTP_NOT_FOUND.html.var
# The default virtual host
@turtlemonvh
turtlemonvh / myapp.conf
Created July 1, 2014 03:51
Apache conf for multiple djangos at different ports, with the main version served over https
WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess site-1 user=myapp group=myapp threads=20
WSGIDaemonProcess site-alt user=myapp group=myapp threads=5
LoadModule ssl_module modules/mod_ssl.so
# Get apache listening on another port
# The "Listen 80" directive is in httpd.conf
Listen 8080
@turtlemonvh
turtlemonvh / README.md
Created October 7, 2014 13:00
Django + mongoengine: Isolated test database

Isolated Test database for Django

This gist contains a few snippets that make creating an isolated test database in Django simple when using mongoengine.

The database identified by settings.MY_TEST_DB_NAME will be deleted every time a test is run.

If your test class needs additional tearDown functionality, make sure to call the super(MyClassName, self).tearDown() method within your overridden version of tearDown to handle deleting the database when you are finished.

@turtlemonvh
turtlemonvh / tornado_all.md
Last active August 31, 2015 15:21
Tornado All

Usage

Call the All class with a list of futures. Returns a future that can be iterated over, yielding each future item in the order it was added.

Inspired by jquery.When.

@turtlemonvh
turtlemonvh / Run Django Tastypie Endpoint Tests
Last active December 19, 2015 14:09
Embracing duck typing
import api
# Create test client
cl = Client()
# Hit all endpoints defined in api file
for _, obj in inspect.getmembers(api):
try:
test_url = '/api/v1/%s/' % obj.Meta.resource_name
response = cl.get(test_url, {'format': 'json'})
@turtlemonvh
turtlemonvh / Django nose settings file
Created July 25, 2013 20:39
A nose specific settings file. Specify this for running tests using the nose test framework. Allows you to run tests using the normal Django test library the usual way. Requires the `nose` and `django-nose` python packages. This version also creates xml coverage and test reports in cobertura and xunit format, respectively.
"""
Specify this settings file to run nose tests format instead of the standard Django test runner.
Useful for getting coverage reports and for getting xunit compaible reports for use with a CI server.
To run all tests:
> python manage.py test --settings=settings_folder.nose_settings apps
To run tests only for a specific app:
> python manage.py test --settings=settings_folder.nose_settings apps.myapp.tests
@turtlemonvh
turtlemonvh / For loop scope test
Created August 7, 2013 21:00
For loop scope test python
for i in range(10):
x = 4
print x
@turtlemonvh
turtlemonvh / JS Scoping
Last active December 20, 2015 18:49
Javascript variable scoping; before and after
for (var i; i<10; i++) {
var x = $("$a-thing");
// ...more work here
}
@turtlemonvh
turtlemonvh / For loop scope test in javascript
Created August 7, 2013 21:08
For loop scope test in javascript
for(var i=1; i<10; i++){var x = 3;};
x