Skip to content

Instantly share code, notes, and snippets.

@affo
affo / flux-bnf.gr
Created May 10, 2019 17:09
Flux language grammar in BNF form
File = File-a File-b StatementList empty
File-a = '' | PackageClause
PackageClause = "package" identifier empty
empty = ''
File-b = '' | ImportList
ImportList = ImportList-a empty
ImportList-a = '' | ImportDeclaration ImportList-a
ImportDeclaration = "import" ImportDeclaration-a string_lit
ImportDeclaration-a = '' | identifier
StatementList = StatementList-a empty
@affo
affo / refactor_tests.go
Last active February 5, 2019 15:04
Refactor tests in Flux
package main
import (
"fmt"
"github.com/influxdata/flux/ast"
"github.com/influxdata/flux/parser"
"io/ioutil"
"os"
"path/filepath"
)
@affo
affo / query.sh
Last active September 14, 2018 14:56
Scripts to start InfluxDB, Flux, and query InfluxDB using Flux with Docker containers.
#!/bin/bash
docker run --net host --rm byrnedo/alpine-curl -XPOST -d "$@" http://localhost:8093/query/
# example query
# '{"query": "from(bucket: \"telegraf\") |> range(start: -10s) |> filter(fn: (r) => r._measurement == \"cpu\" and r._field == \"usage_system\")"}'
# or (unescaped):
# from(bucket: "telegraf") |> range(start: -10s) |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
@affo
affo / flink-conf.yaml
Last active June 13, 2018 07:06
config file for flink
@affo
affo / 2pc.py
Created October 17, 2016 11:06
Implementation of 2 Phase Commit protocol
'''
Implementation of 2 Phase Commit as explained at Wikipedia:
https://en.wikipedia.org/wiki/Two-phase_commit_protocol
'''
import random, logging, time
from threading import Thread, Semaphore, Lock
_fmt = '%(user)s:%(levelname)s >>> %(message)s'
logging.basicConfig(format=_fmt)
LOG = logging.getLogger(__name__)
@affo
affo / clear_blobs.py
Created August 3, 2016 14:48
Python scripts for producing inputs and consuming outputs for an Azure Streaming Analytics Job
from azure.storage.blob import BlockBlobService
from utils import get_storage_credentials
if __name__ == '__main__':
import sys, time
if len(sys.argv) < 2:
print 'Specify container name, please.'
sys.exit(1)
@affo
affo / SocketSpout.java
Last active August 2, 2016 07:34
Apache Storm - implementation for a spout that connects through a TCP socket to a server
import org.apache.storm.spout.SpoutOutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichSpout;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Values;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@affo
affo / dish_classifier.py
Created July 26, 2016 17:11
Naive bayes dish classifier
import random
import numpy as np
# Ok, the point is now to create a naive
# bayes model and stop without accounting
# for the lab...
# We want to model for example the food.
# The food can be terrific, bad, not bad, good
# or awesome: