Skip to content

Instantly share code, notes, and snippets.

View leejones's full-sized avatar

Lee Jones leejones

View GitHub Profile
@leejones
leejones / chef-server-console
Last active June 30, 2016 20:24
In ruby console to interact with the chef server
#!/bin/bash
# loads a pry console to interact with the chef server
# (substitute irb if pry is not available)
bundle exec knife exec -E "require 'pry'; binding.pry"
# type `ls` to see available methods
# to perform a node search for example: `nodes.search("roles:web*")`
#!/bin/bash
host="$1"
workspace="/tmp/memcached-keys/$1"
rm -rf "$workspace"
mkdir -p "$workspace/items"
for item in $(echo "stats items" | nc "$host" 11211 | grep items | awk '{print $2}' | cut -d : -f 2 | sort -n | uniq); do
echo "stats cachedump $item 1000000" | nc "$host" 11211 > "$workspace/items/$item"
@leejones
leejones / example-interactive-console-for-chef-server.md
Last active April 15, 2016 15:52
Interactive Console for Chef Server

If you want to interact with the chef server using the chef gem, you can get an interactive console using knife exec. This can be useful when trying out ideas for automation.

For example, how do I get the IP for a single (random) node for a role (example requires that pry is available):

$> bundle exec knife exec -E "require 'pry'; binding.pry"
[1] pry(#<Object>)> search(:node, 'role:solr-search').shuffle.first.ipaddress
=> "10.45.10.189"
@leejones
leejones / presentation-outline.md
Last active August 29, 2015 14:06
Cache Me If You Can - Presentation Outline

This outline is for a presentation I'm giving at CoderFaire 2014 called Cache Me If You Can on September 21, 2014.

The description that will be listed for the talk:

Using a Content Delivery Network (CDN) can be a great way to improve the performance of your website. In this talk, we will explore the key concepts of HTTP caching and how they are used by a CDN. We will review some of the common challenges and pitfalls in setting up an awesome CDN configuration. To tie it all together, we will walk through how to verify your CDN configuration with automated testing.

intro

  • me
  • what is a CDN?
@leejones
leejones / dot_dot.rb
Last active December 23, 2015 07:29
dot dot dot - simple loading indicator for the console
class DotDot
def self.dot(starting_text = "Loading", completed_text = "Done!")
print starting_text
thread = Thread.new { loop { print '.'; sleep 1 } }
yield if block_given?
Thread.kill(thread)
print "\n"
puts completed_text
end
end
@leejones
leejones / vrunner
Last active December 20, 2015 06:09
#!/usr/bin/env ruby
USAGE = <<-EOS
Run shell commands from vim in another terminal window.
Useful for triggering long-running tasks (tests, vagrant, test-kitchen, etc) without
blocking your vim session.
## Usage
@leejones
leejones / conductor
Created March 18, 2011 14:44
Find passenger processes that have gone off the tracks
#!/bin/sh
current_datetime=$(date | date +'%F-%H%M')
ps aux | grep current | grep -v grep | awk '{print $2}' > /tmp/passengers.$current_datetime.txt
passenger-status | grep PID | awk '{print $2}' >> /tmp/passengers.$current_datetime.txt
likely_freeloaders=$(uniq -u /tmp/passengers.$current_datetime.txt)
echo "Passenger doesn't know if these guys should be on the train"
echo $likely_freeloaders | xargs ps -o pid,command --no-headers
@leejones
leejones / ping_monitor.rb
Created December 28, 2010 20:43
Monitor an address with Scout using ping
class PingMonitor < Scout::Plugin
OPTIONS =<<-EOS
destination:
default: yahoo.com
name: Desitnation
notes: The destination address for ping to check.
EOS
def build_report
ping_output = `ping -c 1 #{option(:destination)}`
@leejones
leejones / passenger_process.rb
Created September 25, 2010 02:49
Remove orphaned passenger processes.
require 'chronic'
class PassengerProcess
attr_accessor :pid, :uptime
def initialize(passenger_status_line)
values = passenger_status_line.match(/PID:\s(\d*).*Uptime:\s*(.*)$/)
@pid = values[1].to_i
@uptime = values[2]
end
@leejones
leejones / test.json
Created February 17, 2010 18:11
test json feed from a tumblr blog
{"tumblelog":{"title":"Rails Machine Status","description":"System and network updates and status information for Rails Machine.\r\n","name":"railsmachine","timezone":"US\/Eastern","cname":"status.railsmachine.com","feeds":[]},"posts-start":0,"posts-total":"97","posts-type":false,"posts":[{"id":390738426,"url":"http:\/\/status.railsmachine.com\/post\/390738426","url-with-slug":"http:\/\/status.railsmachine.com\/post\/390738426\/presidents-day-holiday-support","type":"regular","date-gmt":"2010-02-15 13:08:06 GMT","date":"Mon, 15 Feb 2010 08:08:06","bookmarklet":0,"mobile":0,"feed-item":"","from-feed-id":0,"unix-timestamp":1266239286,"format":"markdown","reblog-key":"mE83wtxd","slug":"presidents-day-holiday-support","regular-title":"Presidents Day Holiday Support","regular-body":"<p>Here at Rails Machine, we\u2019re pretty much a 24\/7\/365 shop. However, every now and then we like to untether ourselves from our laptops and spend time with our friends, family, and loved ones.<\/p>\n\n<p>Today, Monday February 1