Skip to content

Instantly share code, notes, and snippets.

View technige's full-sized avatar
🇪🇺

Nigel Small technige

🇪🇺
View GitHub Profile
@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
@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 / 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
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:
def deprecated(message):
""" Decorator for deprecating functions and methods.
::
@deprecated("'foo' has been deprecated in favour of 'bar'")
def foo(x):
pass
"""
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import print_function
import random
from time import time
from py2neo import Graph, GraphError
@technige
technige / boltproxy.py
Created June 15, 2017 08:54
Simple proxy server for the Bolt protocol.
#!/usr/bin/env python
# coding: utf-8
# Copyright 2017, Nigel Small
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
from dataclasses import dataclass, fields
def neodataclass(_cls=None, *, init=True, repr=True, eq=True, order=False,
unsafe_hash=False, frozen=False):
""" Provides a wrapper around dataclass that silently filters out
any keyword arguments provided to __init__ that do not exist as
fields for that class.
"""
@technige
technige / ocsp-test.java
Last active June 25, 2020 11:36
Tests for OCSP stapling
package tech.nige.demo;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
public class SocketDemo {
@technige
technige / rfc3986.py
Created February 4, 2021 08:59
Implementation of RFC 3986 -- Uniform Resource Identifier (URI): Generic Syntax
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2012-2015, Nigel Small
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0