Skip to content

Instantly share code, notes, and snippets.

View adamhunter's full-sized avatar

Adam Hunter adamhunter

View GitHub Profile
@adamhunter
adamhunter / net_http_timeout_backend.rb
Created June 16, 2011 13:54
getting read_timeout for NetHTTP in > 1.0
require 'riak/client/http_backend'
require 'riak/failed_request'
module Riak
class Client
# Uses the Ruby standard library Net::HTTP to connect to Riak.
# Conforms to the Riak::Client::HTTPBackend interface.
class NetHTTPTimeoutBackend < HTTPBackend
def self.configured?
begin
require 'ripple/associations/proxy'
require 'ripple/associations/one'
module Ripple
module Associations
class OneKeyProxy < Proxy
include One
def replace(doc)
@reflection.verify_type!(doc, owner)
@adamhunter
adamhunter / pbstream.erl
Created April 11, 2011 14:46
riak-erlang-client streaming mapreduce examples
-module(pbstream).
-export([load/1, keys/0, bucket/0, map/3, pb_link/0, pb_link/2]).
-define(QUERY, [{map, {modfun, riak_kv_mapreduce, map_object_value}, <<"filter_notfound">>, true}]).
load(HowMany) ->
lists:foreach(fun(Index) ->
BIndex = list_to_binary(integer_to_list(Index)),
RObj = riakc_obj:new(<<"examples">>, <<"key",BIndex/binary>>, <<"Value ",BIndex/binary>>),
@adamhunter
adamhunter / localstream.erl
Created April 6, 2011 14:35
streaming mapreduce examples with riak local client
-module(localstream).
-export([load/1, keys/0, bucket/0, map/3]).
-define(QUERY, [{map, {modfun, localstream, map}, none, true}]).
load(HowMany) ->
{ok, Client} = riak:local_client(),
lists:foreach(fun(Index) ->
BIndex = list_to_binary(integer_to_list(Index)),
@adamhunter
adamhunter / riak-backup.sh
Created March 8, 2011 15:20
backup any riak node or cluster without logging onto the server the node is running on (but having riak installed)
/usr/local/riak/erts-5.7.5/bin/erl -noshell -name riak_kv_backup@127.0.0.1 -setcookie riak -eval "riak_kv_backup:backup('riak@127.0.0.1', \"/path/to/backup-file.riak\", \"all\")" -s init stop
-# where pages = that_example_hash[:pages]
- pages.each do |page|
.image
%img{ :src => "#{page[:image]}" }
-# the x & y coorinants for the top, left corners have some simple logic to subtract 2 from each to counter
-# the 2px border that's added in the CSS. This makes the focus areas overlay the main image in the right spot.
-# pages.each_pair do ||
- page[:tooltips].each do |tooltip|
:pages =>[{
:name=>"page-1",
:image=>"/pres/images/filler-image.jpg",
:tooltips=>
[{:tooltip=>"focus-1",
:focusY=>45,
:content=>"Lorem ipsum ",
:placement=>"top-left",
:focusHeight=>23,
:x=>20,
@adamhunter
adamhunter / unicorn.sh
Created December 28, 2010 14:29
init.d file for unicorn with rails 3
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deploy/taxscribe/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="/usr/local/bin/unicorn --config-file $APP_ROOT/config/unicorn.server.rb --env production --daemonize $APP_ROOT/config.ru"
action="$1"
#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/home/deploy/public_html/rm/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production
@adamhunter
adamhunter / autoclean.js
Created December 2, 2010 13:38
these are js autocleaners for attributes we'll be validating with a regexp server side
/* autocleaning attributes */
var cleaner = {};
cleaner.phone = function(){
var regex = /[^0-9x]/g;
var value = $(this).val();
if (regex.test(value)) {
$(this).val(value.replace(regex, ''));
}
};
cleaner.date = function(){