Skip to content

Instantly share code, notes, and snippets.

@mks-m
mks-m / graph.rb
Last active August 29, 2015 13:57
# Generates infrastructure graph in DOT format
# Usage:
# $ find . -name '*.pp' | while read file; do cat $file; echo; done | \
# ruby graph.rb > puppet.dot
NODE = /^\s*(class|define|node)(\s+)([\w:]+)/
RELATION = /^\s*(inherits|include)(\s+)([\w:]+)/
RELATION2 = /^\s*class(\s+)\{\s*(['"]?)([\w:]+)/
USAGE = /^\s*([\w:]*[\w])(\s*)\{(\s*)/
IGNORE = %w{file package service cron exec Exec line plugin user group class
require 'rubygems'
require 'puppet/util/autoload'
class Puppet::Util::Autoload
class << self
def search_directories(env=nil)
@search_directories ||= {}
# cache only after initialization
if Puppet.settings.app_defaults_initialized?
@search_directories[env] ||= search_directories_uncached(env)
EventMachine::PeriodicTimer.new(10) do
@redis.keys("*checks*pattern*") do |keys|
@redis.get(keys) do |values|
values.each do |value|
check = MultiJson.load(value) rescue nil
next unless check
if check[:keepalive]
@redis.get("execution:key:#{check[:name]}") do |exec_time|
publish_critical if exec_time < Time.now.to_i - check[:keepalive]
end

Keybase proof

I hereby claim:

  • I am keymone on github.
  • I am keymone (https://keybase.io/keymone) on keybase.
  • I have a public key whose fingerprint is 664F 307D 773C 265C 2054 E89C BAEB B0D1 CA5B 3B07

To claim this, I am signing this object:

@mks-m
mks-m / .vimrc
Last active August 29, 2015 14:20
"
" mv ~/.vim ~/.vim.old; mkdir -p ~/.vim/bundle; pushd ~/.vim/bundle;
" git clone git@github.com:gmarik/Vundle.vim; vim +PluginInstall; popd
"
set nocompatible
" < vundle and plugins >
filetype off
(defn baz [a] a)
; this does something and then returns anonymous function, closure is important
(defn bar [] (let [a b] #(do (baz a) )))
; this gets anonymous function as input and calls it
(defn foo [arg] (arg))
(foo (bar))
% list of {type, flag} tuples
pack(List) -> pack(List, <<>>).
pack([], Ready) -> Ready;
pack([{Type, Flag}|Rest], Ready) ->
Bit = ?MODULE:Type(Flag) - 1,
Size = size(Ready) * 8,
io:format("switch bit ~p in ~p bits~n", [Bit, Size]),
switch(Bit, Size, Rest, Ready).
-module(base32).
-export([encode/1, decode/1]).
encode(Binary) ->
encode(Binary, <<>>).
encode(<<>>, To) -> To;
encode(<<B:1>>, To) -> <<To/binary, (symbol(B)), "====">>;
encode(<<B:2>>, To) -> <<To/binary, (symbol(B)), "=">>;
encode(<<B:3>>, To) -> <<To/binary, (symbol(B)), "=======">>;
#!/bin/env ruby
require 'fileutils'
DRUPAL_MAJOR = 6
puts "Scanning for available drupal versions"
available = Dir['*'].map do |file|
if file =~ /^drupal-#{DRUPAL_MAJOR}\.(\d+)$/
$1.to_i
@mks-m
mks-m / gist:1827669
Created February 14, 2012 15:46
File.each_lines_batch
class IO
def each_lines_batch(batch_size=1000, buffer_size=4096)
lines = []
chunk = ""
while data = file.read(buffer_size)
chunk << data
lines += chunk.lines.to_a
# last line might not be read until it's end