Skip to content

Instantly share code, notes, and snippets.

SELECT
`archive_messages`.`id` AS `id`,
`archive_messages`.`body` AS `body`,
`archive_messages`.`utc` AS `created_at`,
`users`.id AS `user_id`,
`questions`.id AS `question_id`
FROM
archive_collections
INNER JOIN archive_messages
ON archive_collections.id = archive_messages.coll_id
@kernow
kernow / gist:840796
Created February 23, 2011 17:44
mongoose find all
var sys = require('sys')
, mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test_mongoose');
// Models
var Schema = mongoose.Schema;
@kernow
kernow / gist:832554
Created February 17, 2011 20:06
npm config
npm config ls
;_exit = ---sekretz---
auto-activate = "always"
auto-deactivate = true
binroot = "/Users/JamieD/.node/bin"
browser = "open"
color = true
description = true
dev = false
dotnpm = ".npm"
@kernow
kernow / gist:750246
Created December 21, 2010 17:24
search module
module Noodall
module Search
STOPWORDS = ["about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "amoungst", "amount", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "back", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "call", "can", "cannot", "cant", "con", "could", "couldnt", "cry", "describe", "detail", "done", "down", "due", "during", "each", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "had", "has", "hasnt", "have",
criteria.merge!( :_keywords => { :$in => words } )
search_result = collection.map_reduce(search_map(words), search_reduce, {:query => criteria, :finalize => search_finalize})
def search_reduce
"function( key , values ){return { model: values[0]};}"
end
def search_finalize
"function( key , values ){return values.model;}"
>> r = Company.search "teach"
=> [#<Company model: nil, avatar_mime_type: nil, avatar_size: nil, charity: false, address: "", permalink: "Finance/Teaching/conn-ortiz", name: "Conn-Ortiz", _keywords: ["love", "teach", "teaching", "conn", "ortiz"], avatar_uid: nil, created_at: Thu, 16 Dec 2010 11:19:33 UTC +00:00, category: "Teaching", member_id: nil, updated_at: Fri, 17 Dec 2010 16:33:30 UTC +00:00, url: "", _id: BSON::ObjectId('4d09f5c56c78035f08000027'), contact_title: "", tel: "", contact_surname: "", avatar_ext: nil, contact_forename: "", linkedin: nil, description: "We love teaching", avatar_name: nil, email: "ortiz_conn@feeney.uk", sector: "Finance">]
>> r = Company.search "teaching"
=> [#<Company model: {"_id"=>BSON::ObjectId('4d09f5c56c78035f08000027'), "_keywords"=>["love", "teach", "teaching", "conn", "ortiz"], "name"=>"Conn-Ortiz", "permalink"=>"Finance/Teaching/conn-ortiz", "address"=>"", "charity"=>false, "avatar_size"=>nil, "avatar_mime_type"=>nil, "model"=>nil, "category"=>"Teaching", "created_a
# cucumber feature
Scenario: Add member to mailing list
Given I am on the registration page
When I fill in my details
And I check "add me to the mailing list"
And I press "Sign up"
When the account is confirmed the member should be added to the mailing list
Scenario: Don't add member to mailing list
@kernow
kernow / gist:740495
Created December 14, 2010 14:29
problem running selenium with capybara/cucumber
# features/ask_a_question.feature
Feature: Asking a question
@javascript @wip
Scenario Outline: Using the question preview
Given that I am a user
When I go to the homepage
And I fill in "question_title" with "<Question Title>"
And I fill in "question_body" with "<Input Body>"
@kernow
kernow / gist:707239
Created November 19, 2010 21:40
mongoid key issue
class Car
include Mongoid::Document
field :name
field :colour
key :name
end
c1 = Car.new :name => 'bob', :colour => 'red'
@kernow
kernow / gist:706491
Created November 19, 2010 13:07
Mongoid criteria problem?
# I would expect all of the following to return the same results
# Works as expected
Article.find(:first, :conditions => { :slug => 'blah', :published => true })
# On latest beta gem errors with ArgumentError: wrong number of arguments (2 for 0..1)
# Works on latest github master commi
Article.where(:published => true).find(:first, :conditions => { :slug => 'blah' })
# On latest beta gem erros with ArgumentError: wrong number of arguments (2 for 0..1)