Instantly share code, notes, and snippets.

View gist:9919281
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/0.8.20/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'lunr' ]
2 info using npm@1.2.11
3 info using node@v0.8.20
4 verbose read json /Users/olivernightingale/package.json
5 verbose read json /Users/olivernightingale/node_modules/lunr/package.json
6 verbose read json /Users/olivernightingale/package.json
View gist:9919662
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/0.8.20/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'publish',
1 verbose cli '--force' ]
2 info using npm@1.2.11
3 info using node@v0.8.20
4 warn using --force I sure hope you know what you are doing.
5 verbose publish [ '.' ]
6 verbose read json /Users/olivernightingale/code/lunr.js/package.json
View package.json
{
"name": "lunr",
"description": "Simple full-text search in your browser.",
"version": "0.5.0",
"author": "Oliver Nightingale",
"keywords": ["search"],
"homepage": "http://lunrjs.com",
"bugs": "http://github.com/olivernn/lunr.js/issues",
"main": "lunr.js",
"license": "MIT",
View gist:9942353
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/0.8.20/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'lunr' ]
2 info using npm@1.2.11
3 info using node@v0.8.20
4 verbose read json /Users/olivernightingale/package.json
5 verbose read json /Users/olivernightingale/node_modules/lunr/package.json
6 verbose read json /Users/olivernightingale/package.json
View README.md

I think response and collection are the two classes where the bulk of the stuff is happenening, the importer is just an example of the external api. Actually looking back at this I think it could definitly be improved but I guess its an example of how to do it.

I recently did something similar, this time it was streaming a file from s3, but yielding the file line by line. The AWS SDK just gives you the s3 object chunk by chunk as its read from the socket, so I had to buffer and then yield as many lines as possible from each chunk. I returned an enumerator to do this rather than mixing in enumerable, I can't really share this code though, which is a shame cos I thought it was a nice implementation at the time.

View lunr.js
/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.10-issue162
* Copyright (C) 2015 Oliver Nightingale
* MIT Licensed
* @license
*/
;(function(){
/**
View gist:350531
Oliver-Nightingales-MacBook-Pro:capybara-envjs olivernightingale$ rake
(in /Users/olivernightingale/code/capybara-envjs)
warning: couldn't activate the debugging plugin, skipping
warning: couldn't activate the doofus plugin, skipping
warning: couldn't activate the git plugin, skipping
/Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:274:in `include_shared_example_group': Shared Example Group 'has_select' can not be found (RuntimeError)
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:66:in `it_should_behave_like'
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:65:in `each'
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:65:in `it_should_behave_like'
from /Library/Ruby/Gems/1.8/gems/capybara-0.3.6/spec/session_spec.rb:58
View config.ru
require 'rubygems'
require 'rack'
require 'snippets'
require 'mongo'
require 'rackjson'
use Rack::JSON::Resource, :collections => [:notes], :db => Mongo::Connection.new.db("notes")
run lambda { |env| [404, {'Content-Length' => '9', 'Content-Type' => 'text/plain'}, "Not Found"] }
View pbcopy.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>localhost.pbcopy</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/pbcopy</string>
</array>
View gist:593354
Post('post', {}, {
validatesPresenceOf: ['title', 'body'],
validatesLengthOf: [{attr: 'title', min: 20}, { attr: 'body', max: 2000 }]
})