Skip to content

Instantly share code, notes, and snippets.

View danostrowski's full-sized avatar

Dan Ostrowski danostrowski

View GitHub Profile
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-scroll-header-panel/core-scroll-header-panel.html">
<polymer-element name="signup-dialog">
<template>
<style>
:host {
position: absolute;
@danostrowski
danostrowski / mark_dirty.erl
Last active December 15, 2015 13:29
Relatively small Riak pre-commit hook written in Erlang (for me) by @Vagabond and @evanmcc.
% Purpose: I use this pre-commit hook to mark objects in a bucket as "dirty" with secondary indexing.
% I then use a script to scrape out all dirty objects, do some processing, then save them with
% "dirty_bin = false" as an index and the pre-commit hook erases the "dirty_bin" index.
% So in essence it works as: `if dirty_bin = false; del dirty_bin; else dirty_bin = true; end`
%
% To install this pre-commit hook (just like any Riak pre-commit hook in Erlang), you need to create an Erlang file and
% put it in your "basho-patches" directory. For me, on Ubuntu, this was "/usr/lib/riak/lib/basho-patches".
% Once there, you need to compile it to a .beam file. This was helped by using the Riak provided erlc compiler,
% which, on my Ubuntu system, was at "/usr/lib/riak/erts-5.8.5/bin/erlc"
%
@danostrowski
danostrowski / get_item_ctx_mgr.py
Created November 27, 2012 00:44
Context manager to allow getting an item from a dictionary and reusing
class get_item(object):
def __init__(self, d, i):
self.d = d
self.i = i
def __enter__(self):
if self.i in self.d:
return self.d[self.i]
return None
@danostrowski
danostrowski / gist:3861390
Created October 9, 2012 20:59
A quick Riemann stream to emit an event when X events are zero
(defn zero-for-count
"A sliding window of the last n events, emitting an event when all are zero."
[n & children]
(let [window (ref (vec (repeat n nil)))]
(fn [event]
(dosync (alter window pop)
(ref-set window (into [(:metric event)] @window)))
(when (every? (fnil zero? 1) @window)
(call-rescue
(assoc event :description (str "Last " n " metrics have been zero!") :state "warning")
@danostrowski
danostrowski / gist:3861381
Created October 9, 2012 20:58
Quick attempt at sum-for-x-events in Riemann
(defn sum-for-count
"Emit the sum of the last n events."
[n & children]
(let [window (ref (vec (repeat n 0)))]
(fn [event]
; here we guard against putting nils in our vector which doesn't work with (reduce + ... )
(if (and (contains? event :metric)
(not (nil? (:metric event))))
(do
(dosync (alter window pop)