Skip to content

Instantly share code, notes, and snippets.

View chrisglass's full-sized avatar

Chris Glass chrisglass

View GitHub Profile
def dbg(result):
"""
Recover the expression giving the result, and then
print a helpful debug statement showing this
"""
import inspect
frame = inspect.stack()[1]
expr = extract_dbg(frame.code_context[0])
filename = frame.filename.split("/")[-1]
class MonObjet:
blah = 1
something = "something"
instance = MonObjet()
instance.blah
import pytest
def test_something():
# Notice how the "as blah" is missing
with pytest.raises(BlahException):
do_something_that_raises()
with pytest.raises(BlahException):
do_something_that_raises() # This succeeds as if it raised.
import pytest
def test_something():
with pytest.raises(BlahException) as blah:
do_something_that_raises()
with pytest.raises(BlahException) as blah:
do_something_that_raises() # This fails as if it didn't raise
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chrisglass
chrisglass / without_home_protection.txt
Created July 21, 2018 08:03
With home protection turned off
ubuntu@web-caddy-1:/home/caddy$ ls -alih
total 26M
261382 drwxr-xr-x 4 www-data www-data 4.0K Jul 21 07:58 .
1613 drwxr-xr-x 4 root root 4.0K Jul 21 07:54 ..
261384 -rw-r--r-- 1 www-data www-data 220 Apr 4 18:30 .bash_logout
261385 -rw-r--r-- 1 www-data www-data 3.7K Apr 4 18:30 .bashrc
261383 -rw-r--r-- 1 www-data www-data 807 Apr 4 18:30 .profile
261430 drwxr-xr-x 2 www-data www-data 4.0K Jul 21 07:58 .ssh
261402 -rw-r--r-- 1 www-data 1001 22K Jul 20 14:20 CHANGES.txt
261403 -rw-r--r-- 1 www-data 1001 16K Jul 20 14:20 EULA.txt
@chrisglass
chrisglass / with_home_protection.txt
Created July 21, 2018 08:02
With home protection turned on:
ubuntu@web-caddy-1:/home/caddy$ ls -ali
total 26328
261382 drwxr-xr-x 3 www-data www-data 4096 Jul 21 07:55 .
1613 drwxr-xr-x 4 root root 4096 Jul 21 07:54 ..
261384 -rw-r--r-- 1 www-data www-data 220 Apr 4 18:30 .bash_logout
261385 -rw-r--r-- 1 www-data www-data 3771 Apr 4 18:30 .bashrc
261383 -rw-r--r-- 1 www-data www-data 807 Apr 4 18:30 .profile
261402 -rw-r--r-- 1 www-data 1001 22481 Jul 20 14:20 CHANGES.txt
261403 -rw-r--r-- 1 www-data 1001 16345 Jul 20 14:20 EULA.txt
261401 -rw-r--r-- 1 www-data 1001 25261 Jul 20 14:20 LICENSES.txt
if [ $UID -ne 0 ] ; then
echo "Run me as root, baby"
fi
cat > $(git --exec-path)/git-ass << EOF
echo '(‿ˠ‿)'
EOF
chmod +x $(git --exec-path)/git-ass
# PS1 definition!
# Reset
Color_Off="\[\033[0m\]" # Text Reset
# Regular Colors
Black="\[\033[0;30m\]" # Black
Red="\[\033[0;31m\]" # Red
Green="\[\033[0;32m\]" # Green
Yellow="\[\033[0;33m\]" # Yellow
def run(payment=payment, **kwargs): # here the trick is to pass the payment instance as default value.
# Since we have an instance of payment in parameter now, we can inject it in the tests easily.
# Check that the client payed.
try:
contains_payment = payment.contains_payment(_price, request.headers, **kwargs)
except BadRequest as e:
return Response(e.description, BAD_REQUEST)
# Actually do stuff
run_params = request.get_json(silent=False)