Skip to content

Instantly share code, notes, and snippets.

View ostronom's full-sized avatar

Konstantin Kirillov ostronom

View GitHub Profile
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
#/usr/bin/python
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
import random
import grpc
from interface import authentication_pb2
from interface import authentication_pb2_grpc
from interface import groups_pb2
from interface import groups_pb2_grpc
#!/usr/bin/env python2.7
import re
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import Q
class RequestList(object):
def __init__(self, host, method_name):
#self.max_distance =
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import base64
import requests
from PIL import Image
import cStringIO
import os.path
import argparse
#!/usb/bin/env python
import psycopg2
import argparse
def get_xaily_messages(conn, x):
with conn.cursor() as cur:
cur.execute("""
SELECT COUNT(DISTINCT message_id), date_trunc('%s', date) AS quant
FROM history_messages
protected def interleaveDevices(devices: List[Device], busId: EventBusId, msgFactory: Device ⇒ ApiWebRTCSignaling): Future[Unit] = {
(devices |@| devices).tupled.filter(d => d._1.deviceId != d._2.deviceId).foldLeft(FastFuture.successful[Unit](())) {
case (acc, (left, right)) =>
acc *> postFromThisDevice(busId, left, msgFactory(right).toByteArray) *> postFromThisDevice(busId, right, msgFactory(left).toByteArray)
}
}
object UnregisterCredentials {
def unapply(c: UnregisterPushCredentials.Creds): Option[PushCredentials] = c match {
case apple if apple.isApple => apple.apple
case google if google.isGoogle => google.google
case _ => None
}
}
@ostronom
ostronom / wtf.sql
Last active September 8, 2016 12:48
-- CREATE TABLE t (id bigint primary key, c bigint not null)
BEGIN;
UPDATE t SET c=1 WHERE id=1;
INSERT INTO t (id, c) SELECT 1, 1 WHERE NOT EXISTS (SELECT 1 FROM t WHERE id=1);
END;
-- pg 9.4.8
-- contraint violation: duplicate key `id`
@ostronom
ostronom / upickle_key_circe.scala
Last active July 12, 2016 22:12
uPickle derive.key-like behaviour for circe
import cats.data.Xor
import io.circe.parser._
import io.circe._
import io.circe.generic.encoding.DerivedObjectEncoder
import io.circe.syntax._
import io.circe.generic.semiauto._
sealed trait X
case class A(i: Int) extends X
case class B(i: Int) extends X
(ns myns
(:require-macros [cljs.core.async.macros :refer [go-loop]])
(:require [ajax.core :refer [ajax-request raw-response-format]]))
(def html5supported?
(not (or (undefined? js/File)
(undefined? js/Blob)
(undefined? js/FileList)
(not (or js/Blob.prototype.webkitSlice js/Blob.prototype.mozSlice js/Blob.prototype.slice false)))))