Skip to content

Instantly share code, notes, and snippets.

View technige's full-sized avatar
🇪🇺

Nigel Small technige

🇪🇺
View GitHub Profile
try:
unicode
except NameError:
# Python 3
def ustr(s, encoding="utf-8"):
if isinstance(s, str):
return s
try:
return s.decode(encoding)
except AttributeError:
@technige
technige / is_collection.py
Last active August 29, 2015 14:02
Python 2/3 function to detect collection objects
def is_collection(obj):
""" Returns true for any iterable which is not a string or byte sequence.
"""
try:
if isinstance(obj, unicode):
return False
except NameError:
pass
if isinstance(obj, bytes):
return False
@technige
technige / zen_of_cypher.md
Last active April 1, 2020 09:57
The Zen of Cypher

The Zen of Cypher

  • Write functions() in lower case, KEYWORDS in upper.
  • START each keyword clause
    ON a new line.
  • Use either camelCase or snake_case for node identifiers but be consistent.
  • Relationship type names should use UPPER_CASE_AND_UNDERSCORES.
  • Label names should use CamelCaseWithInitialCaps.
  • MATCH (clauses)-->(should)-->(always)-->(use)-->(parentheses)-->(around)-->(nodes)
  • Backticks `cân éscape odd-ch@racter$ & keyw0rd$` but should be a code smell.
@technige
technige / round_robin.py
Last active August 29, 2015 13:57
Python 2 and 3 compatible round_robin function
from itertools import cycle, islice
def round_robin(*iterables):
""" Cycle through a number of iterables, returning
the next item from each in turn.
round_robin('ABC', 'D', 'EF') --> A D E B F C
Original recipe credited to George Sakkis
Python 2/3 cross-compatibility tweak by Nigel Small