Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Thiago Dantas tdantas

🏠
Working from home
View GitHub Profile
@tdantas
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" } }
MongoMapper.connect(Rails.env)
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect if forked
end
@tdantas
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
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 = ''
result.force_encoding("BINARY")
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: '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) }
@tdantas
tdantas / question.js
Created Oct 28, 2012
programming async trick.
View question.js
//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
@tdantas
tdantas / trick
Created Nov 13, 2012
Programming Trick
View trick
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 ##
View first_commit_solution.rb
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
@tdantas
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
end
def watchable
@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.
# USAGE:
#
# 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

Howto

git clone git://gist.github.com/923934.git redisearch

cd redisearch