Skip to content

Instantly share code, notes, and snippets.

View phil-monroe's full-sized avatar

Phil Monroe phil-monroe

View GitHub Profile
@phil-monroe
phil-monroe / publish_batch_worker_completed.rb
Created June 19, 2013 23:33
Sidekiq Middleware to publish to Faye for real time batch status updates
module Sidekiq
module Middleware
module Server
class PublishBatchWorkerCompleted
def call(worker, job, queue)
yield
ensure
begin
unless worker.bid.nil?
@phil-monroe
phil-monroe / faye_debugger.html
Created June 19, 2013 23:42
Super simple Faye Client for debugging purposes Replace url's on line 7 and 18 to the proper endpoints
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Faye demo</title>
<script src="http://localhost:3000/assets/faye-browser.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
</head>
package com.identified.helpers;
import org.apache.avro.Schema;
import org.apache.avro.io.*;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.specific.SpecificRecordBase;
import java.io.ByteArrayOutputStream;
@phil-monroe
phil-monroe / hadoop-logs.sh
Last active December 23, 2015 23:09
Shell function to fetch logs after aggregation
hadoop-logs(){
hdfs dfs -cat "/var/log/hadoop-yarn/apps/$USER/logs/$1/*" | less
}
@phil-monroe
phil-monroe / fib.rb
Last active January 3, 2016 06:29
Fibonacci Sequence Generator with Dynamic Programming
require 'benchmark'
def fib(n)
raise ArgumentError, "needs to be positive! n: #{n}" if n < 0
Array.new(n, 1).tap do |seq|
(2..seq.length-1).each do |idx|
seq[idx] = seq[idx-1] + seq[idx-2]
end if n > 2
end
end
@phil-monroe
phil-monroe / deps2csv.rb
Created January 14, 2014 19:45
Extract maven dependencies to a csv
data = `mvn dependency:tree`
matches = data.split(?\n).map{|l| l.match(/^\[INFO\][\s\|\+\-\\]+(.*)\:(?:jar|war)\:(.*)\:.*$/) }.compact
proj = Dir.pwd.split(?/).last
deps = matches.map{ |m| [ "#{m[1]}:#{m[2]}", m[1].split(?:).first, m[1].split(?:).last, m[2] ] }.uniq.sort
require 'csv'
CSV.open("../#{proj}-dependencies.csv", "w") do |csv|
csv << ["full name", "group id", "artifact id", "version"]
@phil-monroe
phil-monroe / audio.rb
Created February 19, 2014 14:48
Use CoreAudio with Ruby to make a real time CLI level meter and frequency response chart
require "thread"
require "fftw3"
require "coreaudio"
require 'ruby-progressbar'
# progressbar = ProgressBar.create
# progressbar.total = 100
Thread.abort_on_exception = true
@phil-monroe
phil-monroe / update_states.rb
Created October 7, 2014 18:27
A simple way to transform and AR state column into a standardized iso code-ish format
MAPPINGS = {
# format: "COMMON MISTAKE" => "DESIRED STATE SYMBOL"
"OHIO" => "OH",
"CALI" => "CA",
"CALIFORNIA" => "CA"
# and so on...
}
STATES = MAPPINGS.values.uniq # or possibly explicitly defined: %w(OH, CA, ...)
@phil-monroe
phil-monroe / move_invites.script
Created July 13, 2015 18:30
AppleScript to move calendar invites to a folder for OS X Mail
using terms from application "Mail"
on perform mail action with messages theSelectedMessages for rule theRule
repeat with theMessageNum from 1 to count theSelectedMessages
set theMessage to theSelectedMessages's item theMessageNum
if theMessage's source contains "Content-Type: text/calendar" then
set mailbox of theMessage to mailbox "Calendar Invites" of account "my_account"
end if
end repeat
end perform mail action with messages
end using terms from
docker% make docs
/Library/Developer/CommandLineTools/usr/bin/make -C docs docs
docker build -t "docs-base:15058-include-name-in-syslog-tag" .
Sending build context to Docker daemon 7.074 MB
Sending build context to Docker daemon
Step 0 : FROM docs/base:latest
---> 1621828e3ad8
Step 1 : MAINTAINER Mary Anthony <mary@docker.com> (@moxiegirl)
---> Using cache
---> f131e0f60e41