Skip to content

Instantly share code, notes, and snippets.

View pauldix's full-sized avatar

Paul Dix pauldix

View GitHub Profile
@pauldix
pauldix / influx_test.sh
Created February 25, 2015 02:44
InfluxDB test script
printf "creating database\n"
curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
printf "creating retention policy\n"
curl -G http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY myrp ON mydb DURATION 365d REPLICATION 1 DEFAULT"
printf "inserting data\n"
curl -d '{"database" : "mydb", "retentionPolicy" : "myrp", "points": [{"name":"cpu","tags":{"region":"useast","host":"server_1","service":"redis"},"fields":{"value":61}},{"name":"cpu","tags":{"region":"useast","host":"server_2","service":"mysql"},"fields":{"value":53}},{"name":"cpu","tags":{"region":"useast","host":"server_3","service":"apache"},"fields":{"value":80}},{"name":"cpu","tags":{"region":"useast","host":"server_4","service":"nginx"},"fields":{"value":86}},{"name":"cpu","tags":{"region":"useast","host":"server_5","service":"paulapp"},"fields":{"value":87}},{"name":"cpu","tags":{"region":"japan","host":"server_6","service":"redis"},"fields":{"value":10}},{"name":"cpu","tags":{"region":"japan","host":"s
# this shows how to use the update functionality for a single feed with feedzirra
require 'rubygems'
require 'feedzirra'
# I'm using Atom here, but it could be anything. You don't need to know ahead of time.
# It will parse out to the correct format when it updates.
feed_to_update = Feedzirra::Parser::Atom.new
feed_to_udpate.feed_url = some_stored_feed_url
feed_to_update.etag = some_stored_feed_etag
feed_to_update.last_modified = some_stored_feed_last_modified
# This is a code example for the Ruby HTTP library Typhoeus
# here's an example for twitter search
# Including Typhoeus adds http methods like get, put, post, and delete.
# What's more interesting though is the stuff to build up what I call
# remote_methods.
class Twitter
include Typhoeus
remote_defaults :on_success => lambda {|response| JSON.parse(response.body)},
:on_failure => lambda {|response| puts "error code: #{response.code}"},
@pauldix
pauldix / gist:981916
Created May 19, 2011 22:14
Redis SORT command examples
# Optimized for writes, sort on read
# LVC
redis.hset("bonds|1", "bid_price", 96.01)
redis.hset("bonds|1", "ask_price", 97.53)
redis.hset("bonds|2", "bid_price", 95.50)
redis.hset("bonds|2", "ask_price", 98.25)
redis.sadd("bond_ids", 1)
redis.sadd("bond_ids", 2)
package main
import (
"bufio"
"flag"
"fmt"
"github.com/influxdata/influxdb/client"
"math/rand"
"net/url"
"os"
require 'benchmark'
require 'rubygems'
require 'json'
require 'yaml'
include Benchmark
benchmark_iterations = 1
large_single_dimension_array = [42, 123.123] * 5000
large_single_dimension_hash = {}
10000.times do |i|
@pauldix
pauldix / gist:4068851
Created November 13, 2012 22:25
Using Errplane metrics to set up custom thresholding on exception notifications
Errplane.configure do |config|
config.define_custom_exception_data do |black_box|
if black_box.exception.class == ZeroDivisionError
Errplane.report("important_exceptions/#{black_box.exception.class.to_s}")
end
# or just report on all of them and sort it out in the errplane web app
Errplane.report("exception_classes/#{black_box.exception.class.to_s}",
:message => "{Rails.env} - #{black_box.exception.class.to_s} - #{black_box.request_data.to_json}")
@pauldix
pauldix / gist:2830675
Created May 29, 2012 21:00
ideas for fetching
# set the thread pool size and the timeout in seconds.
fetcher = Feedzirra::Fetcher.new({:thread_pool_size => 100, :timeout => 5})
# some feed data objects. also include feed_entry data objects
feeds = [Feed.new({:entries => [], etag => "..", :last_modified => "...", :url => "...", :feed_url => "...", :title => ""})]
# async style
fetcher.get(feeds, :on_success => lambda {|feed, updated_feed| ...}, :on_failure => lambda {|feed, failure_object| ...})
# that returns before finishing fetching the feeds. just adds them to a thread-safe queue to be processed by a worker pool.
# the failure condition could actually call fetcher.get on the failed feed again if you wanted to retry.
@pauldix
pauldix / gist:1081387
Created July 13, 2011 21:34
Y U NO WORK?!!!!
# here's the dealer socket in one process
require 'ffi-rzmq'
@context = ZMQ::Context.new(1)
@sock = @context.socket(ZMQ::XREQ)
@sock.bind("tcp://*:5550")
count = 0
while true do
count += 1
Keyspace: system
Read Count: 11
Read Latency: 1.8718181818181818 ms.
Write Count: 3
Write Latency: 0.021 ms.
Pending Tasks: 0
Column Family: NodeIdInfo
SSTable count: 0
Space used (live): 0
Space used (total): 0