Skip to content

Instantly share code, notes, and snippets.

View zdzolton's full-sized avatar

Zach Zolton zdzolton

View GitHub Profile
function grapp {
find ./app -name "*.rb" |xargs fgrep --color $1;
}
@zdzolton
zdzolton / database.rb
Created May 7, 2009 18:16
CouchDB-Lucene Searching with CouchRest
CouchRest::Database.class_eval do
def search query, options={}
CouchRest.get "#{@uri}/_fti?#{options.merge(:q => query).to_query}"
end
end
@zdzolton
zdzolton / blueprints.rb
Created May 7, 2009 18:10
Machinist-style Blueprint for CouchRest
class CouchRestExt::Model
class << self
def make attributes={}
new(@_blueprint_block.call.merge(attributes)).tap do |obj|
yield obj if block_given?
obj.save
end
end
@zdzolton
zdzolton / model.rb
Created May 7, 2009 18:13
CouchRestExt::Model – for Rails + CouchRest happiness
module CouchRestExt
class Model < CouchRest::ExtendedDocument
include CouchRest::Validation
define_callbacks :validation
def valid?(context = :default)
_run_validation_callbacks do
self.class.validators.execute(context, self)
end
@zdzolton
zdzolton / tweet-spritzer-to-couchdb.rb
Created June 9, 2009 13:59
How to Fill up a CouchDB with Twitter Statuses
require 'rubygems'
require 'json'
gem 'jchris-couchrest'
require 'couchrest'
require 'open3'
COUCHDB_HOST = "http://127.0.0.1:5984"
DB_NAME = 'tweet-spritzer'
SPRITZER_DB = CouchRest.database! "#{COUCHDB_HOST}/#{DB_NAME}"
@zdzolton
zdzolton / rename_rhtml_to_erb_html.rb
Created June 21, 2009 19:29
Renames your RHTML templates to the new file extension convention
Dir.glob('**/*.rhtml') do |rhtml_path|
new_path = rhtml_path.gsub /^(.*)\.rhtml$/, '\1.erb.html'
`git mv #{rhtml_path} #{new_path}`
end
@zdzolton
zdzolton / commit_all.html
Created August 9, 2010 14:11
CouchDB - commit all databases
<!DOCTYPE html>
<html>
<head><title>Commit All Databases</title></head>
<body>
<h1>Commit All Databases</h1>
<p>This script will trigger <tt>_ensure_full_commit</tt> on all databases.</p>
<ul id="databases"></ul>
</body>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
@zdzolton
zdzolton / npm-install-request.sh
Created August 13, 2010 02:30
Installing a Node.js package via NPM
$ npm install request
npm it worked if it ends with ok
npm cli [ 'install', 'request' ]
npm version 0.1.23
npm config file /Users/zach/.npmrc
npm config file /usr/local/Cellar/node/0.1.103/etc/npmrc
npm install pkg request
npm fetch data request
npm GET request
npm install pkg request
$ curl http://npmjs.org/install.sh | sudo sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
115 230 115 230 0 0 5385 0 --:--:-- --:--:-- --:--:-- 11500
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 553k 100 553k 0 0 150k 0 0:00:03 0:00:03 --:--:-- 165k
node cli.js cache clean
npm it worked if it ends with ok
npm cli [ 'cache', 'clean' ]
@zdzolton
zdzolton / gist:1068652
Created July 7, 2011 00:16
Error from CQS SendMessage
Error: Couch response 500 to http://devadmin:foo@localhost:5984/cqs-development/CQS%2FZachary-Zoltons-MacBook-Air-local-development%2F2f7a20debd8f40d9629898d584a30a94: {"error":"case_clause","reason":"{[{<<\"message\">>,<<\"/^CQS\\\\//.test is not a function\">>},\n {<<\"fileName\">>,<<>>},\n {<<\"lineNumber\">>,18},\n {<<\"stack\">>,\n <<\"([object Object],null,[object Object],[object Object])@:18\\n(function (newDoc, oldDoc, userCtx, secObj) {var NAME = \\\"Zachary-Zoltons-MacBook-Air-local-development\\\";var my_msg_id = function (doc) {var for_me = /^CQS\\\\/Zachary-Zoltons-MacBook-Air-local-development\\\\/(.*)$/;var match = for_me.exec(doc._id);if (!match) {return null;}var msg_id = match[1];match = /^([0-9a-f]{32})($|\\\\/(.*)$)/.exec(msg_id);if (!match) {throw {forbidden: \\\"Invalid message id: \\\" + msg_id};}return {id: match[1], extra: match[3]};};if (!/^CQS\\\\//.test(newDoc._id)) {throw {forbidden: \\\"This database is for CQS only\\\"};}var msg_id = mpg-api