Skip to content

Instantly share code, notes, and snippets.

@keturn
keturn / 00_README
Last active June 12, 2018 06:44 — forked from dogeared/00_README
Extracting / Exporting custom emoji from Slack
This builds off the excellent work of @lmarkus & @dogeared.
The scripts below can be used in conjunction with the Slack Emoji Tools Google Chrome extension to export emojis from
one Slack team and import into another team.
Original work here:
* https://gist.github.com/lmarkus/8722f56baf8c47045621
* https://gist.github.com/dogeared/f8af0c03d96f75c8215731a29faf172c
@keturn
keturn / manage-shell-plus-notebook.log
Last active June 20, 2017 23:32
jupyter notebook fails to bind network address
$ docker-compose run --rm django
[I 22:09:16.284 NotebookApp] Writing notebook server cookie secret to /home/django/.local/share/jupyter/runtime/notebook_cookie_secret
Traceback (most recent call last):
File "./notebug/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
@keturn
keturn / fpcursorpagination.py
Last active April 21, 2022 15:21
test for CursorPagination with floating point field
class FloatingPointCursorPagination(CursorPagination):
__rounding_down = decimal.Context(prec=14, rounding=decimal.ROUND_FLOOR)
__rounding_up = decimal.Context(prec=14, rounding=decimal.ROUND_CEILING)
def _get_position_from_instance(self, instance, ordering):
field_name = ordering[0].lstrip('-')
if isinstance(instance, dict):
attr = instance[field_name]
else:
attr = getattr(instance, field_name)
@keturn
keturn / multiple_merge_not_commutative.adoc
Last active July 8, 2016 00:08 — forked from jexp/graph_gist_template.adoc
Cypher: Multiple MERGE statements are not commutative

Muliple Merge Operations are Not Commutative

Note
See graphgist view.

Introduction

@keturn
keturn / cypher_python_syntax_abuse.py
Last active February 21, 2016 06:15
Can we force something like Cypher syntax in to Python? In the tradition of [Sugared DOM](https://gist.github.com/neilj/1532562) and [plumbum](https://pypi.python.org/pypi/plumbum).
# -*- coding: utf-8 -*-
"""THIS IS PROBABLY NOT A GOOD IDEA.
"""
def test_cases():
cases = [
(N(), "()"),
(E, "[]"),
(E[:], "[]"),
@keturn
keturn / ec2-ssh.sh
Last active February 9, 2016 00:46
ssh to an AWS EC2 host by its group name.
#!/bin/bash
# requires AWS CLI: https://aws.amazon.com/cli/
# and jq: https://stedolan.github.io/jq/
set -e
EC2_NAME="$1"
if [ -z "${EC2_NAME}" ] ; then
echo Usage: "$0" '<ec2-name> [ssh args ...]'
fi
shift
EC2_HOSTNAME=$(aws --output json ec2 describe-network-interfaces --filter "Name=group-name,Values=${EC2_NAME}" |
@keturn
keturn / rescope.py
Created February 8, 2016 09:16
Nested scope, but not nested visually?
"""
Can we have a "nested function", but have definition of the inner function not lexically within its parent?
Question by https://www.reddit.com/r/compsci/comments/44o18l/do_any_programming_languages_allow_you_to_give/
This file was written as an intellectual exercise. I do not recommend using it. Ever.
The implementation below works by using the descriptor protocol to return a newly bound method every time the outer
function makes a new reference to the inner function, and uses the outer method's *locals* as the inner method's
*globals*. The primary disadvantage here is that means the inner method doesn't have access to the actual globals.
@keturn
keturn / dunder_str_unicode.py
Last active November 11, 2015 21:05
the perils of returning unicode from __str__ in Python 2 compatible code
# -*- coding: utf-8 -*-
from django.utils.encoding import force_str
class BadStr(object):
def __init__(self, content):
self.content = content
def __str__(self):
assert isinstance(self.content, unicode), "returning it from __str__ anyway"
@keturn
keturn / run-pyrasite.md
Created June 30, 2015 04:38
pyrasite in 2015
@keturn
keturn / test_views.py
Last active December 31, 2015 16:39
dangjo view tests and URLs
from django.test import TestCase
from django.conf.urlresolvers impor resolve, reverse
from myviews import ThingView
class TestThingView(TestCase):
def setUp(self):
url_name = 'thing_view'
kwargs = {'pk': '5'}