git clone git://gist.github.com/923934.git redisearch
cd redisearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoMapper.config = { | |
Rails.env => { 'uri' => ENV['MONGOHQ_URL'] || | |
"mongodb://localhost/rubyconf_simple_app-#{Rails.env}-1" } } | |
MongoMapper.connect(Rails.env) | |
if defined?(PhusionPassenger) | |
PhusionPassenger.on_event(:starting_worker_process) do |forked| | |
MongoMapper.connection.connect if forked | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// everyone's new favorite closure pattern: | |
(function(window,document,undefined){ ... })(this,this.document); | |
// when minified: | |
(function(w,d,u){ ... })(this,this.document); | |
// which means all uses of window/document/undefined inside the closure | |
// will be single-lettered, so big gains in minification. | |
// it also will speed up scope chain traversal a tiny tiny little bit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'redis' | |
require 'json' | |
require 'date' | |
class String | |
def &(str) | |
result = '' | |
result.force_encoding("BINARY") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
require "spec_helper" | |
describe Notification do | |
describe "new_question" do | |
let(:user) { Factory.create(:user, name: 'Dart Vader', email: 'dart@example.com') } | |
let(:category) { Factory.create(:category, name: 'Saúde') } | |
let(:owner) { Factory.create(:user, name: 'Jaspion') } | |
let(:question) { Factory.create(:question, user: owner, category: category) } | |
let(:mailer) { Notification.new_question(question.id, user.id) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Question: | |
// Environment: NodeJS | |
// Lets suppose that you have a collection of items, and your function must persist all items using the | |
//database.insert(item, callback ) function. When you finish the task, you should call the callback function. | |
// If one item raise a error, the callback(err) must be called and never call the callback anymore. | |
function saveBulk(items, callback) { | |
// Your code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Objective: | |
Write a program that prints out a multiplication table of the first 10 prime numbers. | |
The program must run from the command line and print to screen 1 table. | |
Across the top and down the left side should be the 10 primes, and the body of the table should | |
contain the product of multiplying these numbers. | |
Please include Rspec tests. | |
P.s. the prime numbers should be calculated, rather than using Ruby’s Prime Method | |
## OUTPUT ## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fixnum | |
def prime? | |
(2..Math.sqrt(self).to_i).each do |number| | |
return false if (self % number == 0) | |
end | |
true | |
end | |
end | |
class PrimeMatrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Flavour | |
module ClassMethods | |
def watch(&block) | |
@watchable = block | |
end | |
def watchable | |
@watchable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build an inverted index for a full-text search engine with Redis. | |
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License. | |
# USAGE: | |
# | |
# ruby invertedindex.rb add somedir/*.c | |
# ruby invertedindex.rb add somedir/*.txt | |
# ruby search your query string | |
require 'rubygems' | |
require 'redis' |
OlderNewer