Skip to content

Instantly share code, notes, and snippets.

View drbobbeaty's full-sized avatar

Bob Beaty drbobbeaty

View GitHub Profile
@drbobbeaty
drbobbeaty / nimbus.clj
Created September 8, 2014 14:07
Clojure code to get the bolt metrics for a Storm Topology
(ns gym.storm.nimbus
"Namespace for exercising Nimbus to find out facts about the specific storm
cluster. This data can be used to monitor the cluster and look at stats in
a way that's got very low load on the overall system."
(:require [backtype.storm.clojure :refer :all]
[backtype.storm.config :refer :all]
[backtype.storm.ui.core :refer :all]
[clj-endpoints :as ep]
[clj-endpoints.persistence.redis :refer [wcar]]
[clj-endpoints.util :as util]
@drbobbeaty
drbobbeaty / server.clj
Last active March 10, 2022 12:24
Simple clojure Ring example
(ns performance.server
"The routes for the web server."
(:require [cheshire.core :as json]
[clj-time.core :refer [now]]
[clojure.tools.logging :refer [infof warn warnf error errorf]]
[compojure
[core :refer [defroutes GET POST]]
[handler :as handler]]
[ring.middleware.jsonp :refer [wrap-json-with-padding]]
[ring.middleware.params :refer [wrap-params]]
@drbobbeaty
drbobbeaty / REPL.txt
Last active December 14, 2015 16:39
Problem with asynchronously calls
dark-magic.main=> (require 'slam :reload-all)
nil
dark-magic.main=> (slam/unbound 4)
nil
dark-magic.main=> (slam/bound 4)
nil
@drbobbeaty
drbobbeaty / fast_child_loader.sql
Created February 4, 2013 16:52
I needed a way to load up the children of a very large table with decent referential integrity a lot faster than joins and sub-selects. What I came up with was a stored procedure that loops over the parent ids, and loads up the results into a temp table.
create or replace function locations_for_demand_set(ds_id uuid)
returns table(id uuid,
demand_id uuid,
is_anchor_zip boolean,
latitude double precision,
longitude double precision,
name varchar,
subdivision_rank varchar,
type varchar,
division_permalink varchar,
@drbobbeaty
drbobbeaty / dark-magic.html
Last active December 11, 2015 13:29
Nice little page for getting and displaying JSON for the user. It uses a slick little classifier for the syntax highlighting and then CSS classes to set the attributes of those tags. Very nice.
<html>
<head>
<title>Dark Magic Query Tools for Quantum Lead</title>
<link href='//fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
<script type='text/javascript' src='zingchart/resources/jquery.min.js'></script>
<script type='text/javascript'>
// This is a clever little function I found that does a very simplistic
// syntax coloring scheme for JSON. What it really is doing is to classify
// all the elements, and then with CSS we can color them. Very slick.
function syntaxHighlight(json) {
@drbobbeaty
drbobbeaty / vacuum.sh
Last active December 11, 2015 04:39
Nice script that cleans up stale deployment jars after 30 days, but _always_ preserves the last 5 so you can go back to any one of them if need be. Great for jruby and clojure projects where it's all in a single jar.
#!/bin/bash
#
# This script clears out all the "stale" jars that we no longer need.
# They have to be AT LEAST 30 days old, and we MUST keep the last 5.
# Other than that, they can go.
#
#
# Set upt he environment for this - as we do in all scripts
@drbobbeaty
drbobbeaty / gist:4052640
Created November 10, 2012 21:45
JRuby extensions to Enumerable for parallel processing and more
require 'java'
java_import 'java.util.concurrent.Executors'
java_import 'java.util.concurrent.TimeUnit'
module Enumerable
# From activesupport/lib/active_support/core_ext/enumerable.rb
def sum(identity = 0, &block)
if block_given?
map(&block).sum(identity)
else
@drbobbeaty
drbobbeaty / database.rb
Created November 9, 2012 21:02
Optionally queueing Ruby CouchDB/CouchRest client
# encoding: utf-8
require 'quantum_lead/application'
require 'singleton'
require 'logger'
require 'version'
require 'couchrest'
require 'java'
java_import 'java.util.concurrent.ConcurrentLinkedQueue'
class Database
@drbobbeaty
drbobbeaty / campfire.sh
Created October 9, 2012 21:45
Bash script to send stdin to a Campfire room using curl API
#!/bin/bash
#
# This script takes stdin and sends it to the QuantumLead Campfire room as
# Canadarm. This can take an optional '-p' argument so that the stdin will
# be treated as a "paste" and go in as a fix-edwidth font paste. Otherwise,
# it'll appear as a simple proportional font "message"
#
# Let's make sure all the commands we need are accessible to us...
@drbobbeaty
drbobbeaty / unpinned_merchants.html
Created September 25, 2012 13:57
Example of creating a CSV download from Google Visualization Table
<html>
<head>
<title>Unpinned Merchants</title>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript' src='zingchart/resources/jquery.min.js'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(reload_executions);
// set up the fixed locations and paths for this metric visualization.
// we need to be able to pick the server (prod, uat, dev).