Skip to content

Instantly share code, notes, and snippets.

View johnthethird's full-sized avatar

John Lynch johnthethird

View GitHub Profile
script/plugin install git://github.com/myobie/htmldiff.git
# bottom of environment.rb
require 'htmldiff'
# in model
class Page < ActiveRecord::Base
extend HTMLDiff
end
# Read the log into an array.
@mylog = IO.readlines("path/to/log/file.log")
Now, if you want to get rid of the ANSI escape codes from the log (assuming you are accessing your application/database logs) you will have to use regular expressions. There are two ways of doing this. The first is to get rid of the codes after you read the log file, or do it as you display.
Here are the examples:
# Read the log into an array.
@mylog = IO.readlines("/path/to/log/file.log")
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s
test.rb
-----------------------------------
#!/usr/local/bin/ruby
require 'ripple'
# Create a client interface
client = Riak::Client.new
# Retrieve a bucket
bucket = client.bucket("doc") # a Riak::Bucket
/**
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out http://gist.github.com/186325
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons
client = Riak::Client.new()
bucket = client.bucket('MyBucket')
my_json_obj = bucket.get('MyKey')
my_json_obj.content_type #=> "application/json"
my_json_obj.data.to_json #=> {"name":=>"Joe"}
my_json_obj.data.to_s #=> nameJoe
Should RObject.data.to_s be aliased to .to_json when we know the content_type is json?
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;
module Riak
class RObject
def reload_headers
return {} if @data == "_LAZY_LOADED_"
{}.tap do |h|
h['If-None-Match'] = @etag if @etag.present?
h['If-Modified-Since'] = @last_modified.httpdate if @last_modified.present?
end
end
# This patch to the Ripple gem will properly escape key names with slashes and + signs
# in them. Nice for trying to store a file directory structure in Riak.
module Riak
class Client
class HTTPBackend
def path(*segments)
query = segments.extract_options!.to_param
uri = root_uri.merge(URI.escape(segments.join("/").gsub(/\/+/, "/").sub(/^\//, ''))).tap do |u|
u.query = query if query.present?
end
#!/bin/bash
# ubuntu @ ec2 (canonical official ubuntu-images-us - I grabbed 64bit)
# then login as 'ubuntu' & start working - however this should be reproducable
# anywhere you have tip riak installed...
sudo perl -p -i -e 's/universe$/universe multiverse/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade -y