Skip to content

Instantly share code, notes, and snippets.

@seancribbs
seancribbs / simple_load_views.rb
Created October 23, 2009 15:47
A simple way to load your CouchDB views from the filesystem in Ruby.
# CouchApp is busted. Let's do it ourselves.
module CouchRest
class Design < Document
def load_views_from(path)
self['views'] ||= {}
Dir["#{path}/views/*/*.js"].each do |js|
view_name = js.split(/\//)[-2]
function = js.split(/\//)[-1].split('.').first
content = File.read(js)
self['views'][view_name] ||= {}
alias ga='git add'
alias gb='git branch'
alias gci='git commit'
alias gco='git checkout'
alias gdel='git status | grep deleted: | sed '\''s/\#.*deleted: //'\'' | xargs git rm'
alias gf='git fetch'
alias gfo='git fetch origin'
alias gfom='git fetch origin master'
alias gm='git merge'
alias gp='git push'
<p><strong>J.D. Lafrance</strong><br /><script type="text/javascript">
<script type="text/javascript"><br />
&lt;![<span class="caps">CDATA</span>[</p>
<p>function hiveware_enkoder(){var i,j,x,y,x=<br />
&#8220;x=&#8221;783d22793e23337a323537793e64375d23373237353737386737333734383237363766&quot; +<br />
&#8220;376537343736373635663831373533353766383a3738386738333731373a38323335376637&#8221; +<br />
&#8220;363367383933333733343834643764333233673731373234393866333337333336373a3437&#8221; +<br />
&#8220;346334653631346433635d2333373c7a65373e283237283c3a3767706438732935376a3e67&#8221; +<br />
&#8220;34313c62376a3d6237792f35376d6664376f683237756937383c6a33372c3e3237332a6637&#8221; +<br />
&#8220;7c7a34372c3e3635766f31376674353764623a377166673829283137262832332c7966372f&#8221; +<br />
app/views/home/show.html.haml:61: syntax error, unexpected kENSURE, expecting kEND
app/views/home/show.html.haml:63: syntax error, unexpected $end, expecting kEND
@seancribbs
seancribbs / extract_safari_cache.rb
Created December 15, 2009 00:56
Extracts files you're looking for out of Safari's web cache
require 'rubygems'
require 'active_record'
# Open Safari's sqlite3 cache database
arb = ActiveRecord::Base
arb.establish_connection(
:adapter => "sqlite3",
:database => File.join(ENV['HOME'], 'Library', 'Caches', 'com.apple.Safari', 'Cache.db'))
# How to match files (LIKE string)
Author.find_by_sql "SELECT * FROM authors INNER JOIN extensions ON authors.id = extensions.author_id GROUP BY extensions.author_id HAVING COUNT(extensions.author_id) > 0"
# Had to add the :group key to produce a unique set.
# Removing `:include => :extensions` also reduced this from two queries to one.
require_recipe 'erlang'
execute "Add RabbitMQ deb repo" do
command 'echo "deb http://www.rabbitmq.com/debian/ testing main" > /etc/apt/sources.list.d/rabbitmq'
creates "/etc/apt/sources.list.d/rabbitmq"
notifies :run, resources(:execute => "apt-get update"), :immediate
end
execute "Add RabbitMQ key" do
command "apt-key add /root/rabbitmq-signing-key-public.asc"
$ curl -v http://localhost:8098/raw/foo/bar/_,next,_/_,previous,1
* About to connect() to localhost port 8098 (#0)
* Trying ::1... Connection refused
* Trying fe80::1... Connection refused
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8098 (#0)
> GET /raw/foo/bar/_,next,_/_,previous,1 HTTP/1.1
> User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
> Host: localhost:8098
> Accept: */*
>> c = Riak::Client.new :host => "192.168.1.105"
=> #<Riak::Client http://192.168.1.105:8098>
>> mr = Riak::MapReduce.new(c)
=> #<Riak::MapReduce:0x19a8868 @client=#<Riak::Client http://192.168.1.105:8098>, @inputs=[], @query=[]>
>> 10.times {|i| mr.add("stress", "test#{i+1}") }
=> 10
>> mr.map("function(v, _, _) { var value = v[\"values\"][0][\"data\"]; return [parseInt(value)]; }").reduce("Riak.reduceSum", :keep => true)
=> #<Riak::MapReduce:0x19a8868 @client=#<Riak::Client http://192.168.1.105:8098>, @inputs=[["stress", "test1"], ["stress", "test2"], ["stress", "test3"], ["stress", "test4"], ["stress", "test5"], ["stress", "test6"], ["stress", "test7"], ["stress", "test8"], ["stress", "test9"], ["stress", "test10"]], @query=[#<Riak::MapReduce::Phase:0x198e364 @arg=nil, @type=:map, @keep=false, @function="function(v, _, _) { var value = v[\"values\"][0][\"data\"]; return [parseInt(value)]; }", @language="javascript">, #<Riak::MapReduce::Phase:0x198e260 @arg=nil, @type=:reduce, @keep=true, @function="Riak.re
var Ripple = {
mapByFields: function(value, keyData, fields){
var object = Riak.mapValuesJson(value)[0];
for(field in fields) {
if(object[field] != fields[field])
return [];
}
return [object];
},
filterByConditions: function(value, keyData, conditions){