This gist has been migrated to a real repository: https://github.com/wolever/openssl-x509-scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| adminreverse from here http://djangosnippets.org/snippets/2032/ | |
| changed for working with ForeignKeys | |
| ''' | |
| ''' | |
| reverseadmin | |
| ============ | |
| Module that makes django admin handle OneToOneFields in a better way. | |
| A common use case for one-to-one relationships is to "embed" a model | |
| inside another one. For example, a Person may have multiple foreign |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED | |
| local scrollMouseButton = 3 | |
| local deferred = false | |
| overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e) | |
| -- print(hs.eventtap.event.properties['mouseEventButtonNumber']) | |
| local mouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber']) | |
| if mouseButton == scrollMouseButton then | |
| deferred = true | |
| return true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A simple watchdog for long running processes which may stall for some reason or | |
| another. | |
| If the main thread hasn't logged progress (by updating | |
| ``self.last_progress_time``) in WATCHDOG_HARD_KILL_TIMEOUT, the watchdog | |
| thread will log an error containing the stack trace of all currently running | |
| threads then use ``kill -9`` to kill the main process. | |
| Assumes that a process monitor like supervisor or systemd will then restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * ObjectType matches any "regular" object. | |
| * | |
| * For example: | |
| * > {} satisfies ObjectType | |
| * > { a: 1, b: 2 } satisfies ObjectType | |
| * > [] satisfies ObjectType | |
| * > null satisfies ObjectType | |
| * TypeError: 'null' does not satisfy 'ObjectType'. | |
| * > undefined satisfies ObjectType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Catches any exception which might be raised by a promise and returns a | |
| * tuple of [result, error], where either the result or the error will be | |
| * undefined: | |
| * | |
| * let [res, error] = await maybe(someApi.get(...)) | |
| * if (err) { | |
| * return `Oh no there was an error: ${err}` | |
| * } | |
| * console.log('The result:', res) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Call `setup_ssh_socket` to setup the control socket (function will return once | |
| # the socket is ready to go), and `ssh_target` will connect using the control socket. | |
| # Assumes TARGET_HOST variable is set. | |
| # The connection is automatically closed when the script exists. | |
| # TARGET_HOST="wolever.net" | |
| # setup_ssh_control_socket | |
| # ssh_target "hostname" | |
| debug() { | |
| echo "DEBUG: $*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| nodes="-nodes" | |
| if [[ "$1" == "-des" ]]; then | |
| nodes="" | |
| shift | |
| fi | |
| if [[ ! "$1" || ! "$2" || "$1" =~ "^-" ]]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A quick but effective hack for disabling migrations while running Django tests. | |
| # Put this in settings.py below the existing MIGRATION_MODULES definition, if that exists: | |
| if "test" in sys.argv[1:]: | |
| class DisableMigrations(object): | |
| def __contains__(self, item): | |
| return True | |
| def __getitem__(self, item): | |
| return "notmigrations" |
- Put these files in
yourapp/testing/ - Install:
- django-nose: https://django-nose.readthedocs.org/en/latest/installation.html
- model_mommy:
pip install model-mommy
- Run tests with
python manage.py test, or test specific files or directories withpython manage.py test myapp/tests/test_models.py
- Test cases which use the database must subclass
MyAppTestCase, but other test can use test functions, generators, and everything else supported by nose: https://nose.readthedocs.org/en/latest/writing_tests.html
NewerOlder