Skip to content

Instantly share code, notes, and snippets.

View robinedwards's full-sized avatar

Robin Edwards robinedwards

View GitHub Profile
#lang racket/base
(require plot)
(require racket/gui)
(define temp-readings (make-hash))
(define (list-thermal-zones)
@robinedwards
robinedwards / selective_retry.py
Created January 27, 2020 09:51
Selective retry operator
class SelectiveRetryPythonOperator(PythonOperator):
"""
Allows only retrying certain types of exception by altering max_tries
"""
def __init__(self,
retry_for=None,
func_args=None,
func_kwargs=None,
class ProbeOperator(PythonOperator):
def __init__(self, *args, attempts=None, interval=None, probe_timeout=None, **kwargs):
assert isinstance(attempts, int)
assert isinstance(interval, timedelta)
assert isinstance(probe_timeout, timedelta)
self.probe_timeout = probe_timeout
self.attempts = attempts
kwargs['retries'] = attempts
@robinedwards
robinedwards / test_subdags.py
Created September 5, 2018 14:49
handling subdag retries
from datetime import datetime
from airflow.models import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
from airflow.operators.subdag_operator import SubDagOperator
DAG_NAME = 'example_subdag_operator'
@robinedwards
robinedwards / cypher.vim
Last active December 14, 2015 11:59
Create binding for execute neo4j cypher and show results in separate vim window. Make sure you have installed py2neo first: pip install py2neo You can change the format of the results with the -f flag
" Run cypher query and return result
function! EvalCypher()
let src = expand("%")
let dst = tempname()
execute ":silent !cat " . src . " | cypher -f json -H localhost &> " . dst
execute ":pedit! " . dst
execute ":redraw!"
wincmd P
setlocal syntax=javascript
retab
# nodes.csv
category name age size
Person
Company
Google 1000
Amit Gupta 15
# rels.csv
start end type __instance__:boolean
1 4 PERSON true
from neomodel import StructuredNode, StringProperty, IntegerProperty
class Person(StructuredNode):
facebookid = StringProperty(unique_index=True)
age = IntegerProperty(index=True, default=0)
Person(facebookid="f434234ef", age=8).save()
Person(facebookid="f434234ef", age=8).save() # raises a UniqueProperty exception
from .. import RelationshipTo, StructuredNode, StringProperty
from .core import NodeIndexManager
class Language(StructuredNode):
code = StringProperty(unique_index=True)
name = StringProperty()
class LocalisedIndex(NodeIndexManager):
""" Only return results in current language """
START country_cat = node:Category(category="Country"),
nationality_cat = node:Category(category="Nationality"),
passport_cat = node:Category(category="Passport")
CREATE UNIQUE
(country_cat)-[:COUNTRY {__instance__: true}]->(country {code: 'GB'})
-[:NATIONALITY]->
(nationality {code: 'GB-GB'})
-[:PASSPORT]->
(passport {code: 'GB-GB-P'}),
@classmethod
def lookup(cls, uid=None):
lang = translation.get_language().replace('-', '_')
query = """
START lang = node:Language(code:{lang}),
node = node:%s(uid:{uid})
MATCH (node)-[:LANGUAGE]->(lang)
RETURN node
""" % (cls.__name__)
r = cls.category().cypher(query, {'uid': uid, 'lang': lang})[0]