Skip to content

Instantly share code, notes, and snippets.

@siyo
Last active December 14, 2015 14:18
Show Gist options
  • Save siyo/5099452 to your computer and use it in GitHub Desktop.
Save siyo/5099452 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# simple blink(1) earthquake.gem plugin
#
Earthquake.init do
once do
class Blink1Notify
#
# xterm colors
#
# ANSI escape code - Wikipedia, the free encyclopedia :
# http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
#
ANSI_NORMAL_COLORS = [
[205, 0, 0], # Red
[ 0, 205, 0], # Green
[205, 205, 0], # Yellow
[ 0, 0, 238], # Blue
[205, 0, 205], # Magenta
[ 0, 205, 205] # Cyan
]
ANSI_BRIGHT_COLORS = [
[255, 0, 0], # Red
[ 0, 255, 0], # Green
[255, 255, 0], # Yellow
[ 92, 92, 255], # Blue
[255, 0, 255], # Magenta
[ 0, 255, 255] # Cyan
]
MIN_NORMAL_COLOR = 31
MIN_BRIGHT_COLOR = 91
MAX_NORMAL_COLOR = MIN_NORMAL_COLOR + ANSI_NORMAL_COLORS.size - 1
MAX_BRIGHT_COLOR = MIN_BRIGHT_COLOR + ANSI_BRIGHT_COLORS.size - 1
CMD = "blinK1-tool"
OPT_FADE = 10
OPT_DELAY = 200
OPT_BLINK = 1
def setup
system("%s --off -q" % [CMD])
end
def notifier(ansi_color)
rgb = case ansi_color
when MIN_NORMAL_COLOR .. MAX_NORMAL_COLOR
ANSI_NORMAL_COLORS[ ansi_color - MIN_NORMAL_COLOR ]
when MIN_BRIGHT_COLOR .. MAX_BRIGHT_COLOR
ANSI_BRIGHT_COLORS[ ansi_color - MIN_BRIGHT_COLOR ]
else
[0,0,0]
end
cmd = "%s -m %d -t %d --rgb %s --blink %d -q" % [ CMD, OPT_FADE, OPT_DELAY, rgb.join(','), OPT_BLINK ]
return lambda { system cmd }
end
end
Blink1Notify.new.setup
end
output do |item|
next if item.nil? || item["user"].nil?
screen_name = item["user"]["screen_name"]
color = color_of(screen_name)
EM.defer( Blink1Notify.new.notifier color )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment