Skip to content

Instantly share code, notes, and snippets.

Working from home

Thiago Dantas tdantas

Working from home
View GitHub Profile
tdantas / mongo.rb
Created Nov 8, 2011 — forked from rodriguezartav/mongo.rb
config/initializers/mongo.rb it setups mongomapper to be used locally and in heroku with MongoHQ
View mongo.rb
MongoMapper.config = {
Rails.env => { 'uri' => ENV['MONGOHQ_URL'] ||
"mongodb://localhost/rubyconf_simple_app-#{Rails.env}-1" } }
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect if forked
tdantas / gist:1588474
Created Jan 10, 2012 — forked from dshaw/gist:378192
(function(window,document,undefined){ ... })(this,this.document);
View gist:1588474
// 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.
tdantas / app.rb
Created Jun 28, 2012 — forked from cpatni/app.rb
unique calculation using redis
View app.rb
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
View new_mailer_spec.rb
# -*- encoding : utf-8 -*-
require "spec_helper"
describe Notification do
describe "new_question" do
let(:user) { Factory.create(:user, name: 'Dart Vader', email: '') }
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(, }
tdantas / question.js
Created Oct 28, 2012
programming async trick.
View question.js
// 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
tdantas / trick
Created Nov 13, 2012
Programming Trick
View trick
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 ##
View first_commit_solution.rb
class Fixnum
def prime?
(2..Math.sqrt(self).to_i).each do |number|
return false if (self % number == 0)
class PrimeMatrix
tdantas / Flavour.rb
Created Nov 16, 2012
Flavour - The module to avoid ifs when your model is State driven behaviour
View Flavour.rb
module Flavour
module ClassMethods
def watch(&block)
@watchable = block
def watchable
View gist:4510153
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
View _readme.markdown

Simplistic Full-Text Search With Redis's Sorted Sets


git clone git:// redisearch

cd redisearch