Skip to content

Instantly share code, notes, and snippets.

View lgs's full-sized avatar

Luca G. Soave lgs

View GitHub Profile
@lgs
lgs / gist:3068455
Created July 7, 2012 22:50 — forked from adamlwatson/gist:1371577
Mongoid connection pooling in Goliath
require 'em-synchrony/em-mongo'
require 'mongoid'
mongoid_conn = Mongo::Connection.new 'localhost', 27017, :pool_size => 10
Mongoid.configure do |config|
begin
config.master = mongoid_conn.db('dbname')
rescue Exception=>err
abort "An error occurred while creating the mongoid connection pool: #{err}"
end
@lgs
lgs / gist:3135206
Created July 18, 2012 09:19
Moped Serialization Speed Test
require 'moped'
require 'bson'
object = {a: 1234, b: '1234', c:[1,2,3,4], d: {a:1, b:2, c:3, d: 4}, f: {a: 1234, b: '1234', c:[1,2,3,4], d: {a:1, b:2, c:3, d: 4}}, g:'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}
time = 0
10000.times do
t = Time.now
Moped::BSON::Document.serialize object
time += Time.now - t
@lgs
lgs / development.rb
Created July 22, 2012 22:01 — forked from MyArtChannel/development.rb
Use Pry as IRB replacement in rails 3 console
# Add this to the end of your development.rb and add
#
# gem 'pry'
#
# to your Gemfile and run bundle to install.
silence_warnings do
begin
require 'pry'
IRB = Pry
@lgs
lgs / GEMFILE
Created August 4, 2012 09:58 — forked from himynameisjonas/GEMFILE
Flickr plugin to Jekyll (blog-aware, static site generator)
source :rubygems
gem 'RedCloth'
gem 'jekyll'
gem 'fleakr'
@lgs
lgs / JekyllListAllPosts.html
Created August 6, 2012 09:15 — forked from erjjones/JekyllListAllPosts.html
Jekyll List All Posts
{% for post in site.posts %}
<h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
<p><small><strong>{{ post.date | date: "%B %e, %Y" }}</strong> . {{ post.category }} . <a href="http://erjjones.github.com{{ post.url }}#disqus_thread"></a></small></p>
{% endfor %}
@lgs
lgs / mongoid_bench.rb
Created August 8, 2012 15:24 — forked from pkieltyka/mongoid_bench.rb
Mongoid / Mongo bench with Celluloid::IO + nio4r
=begin
# Gemfile:
source :rubygems
gem 'celluloid', :git => 'git://github.com/tarcieri/celluloid.git'
gem 'celluloid-io', :git => 'git://github.com/tarcieri/celluloid-io.git'
gem 'mongoid'
gem 'bson_ext'
=end
require 'bundler'
@lgs
lgs / README.markdown
Created August 9, 2012 07:22 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

@lgs
lgs / auth_and_rate_limit.rb
Created August 9, 2012 21:53 — forked from mrflip/auth_and_rate_limit.rb
API key authentication + rate limiting in Goliath using MongoDB (incomplete sketch)
#!/usr/bin/env ruby
$: << File.join(File.dirname(__FILE__), '../lib')
require 'goliath'
require 'em-mongo'
require 'em-http'
require 'em-synchrony/em-http'
require 'yajl/json_gem'
require 'goliath/synchrony/mongo_receiver' # has the aroundware logic for talking to mongodb
require File.join(File.dirname(__FILE__), 'auth_receiver')
@lgs
lgs / Gemfile
Created August 9, 2012 21:58 — forked from rinaldifonseca/Gemfile
Goliath.io with Grape and MongoDB
gem 'mongo'
gem 'em-mongo'
gem 'bson_ext'
gem 'goliath'
gem 'grape'
@lgs
lgs / oauth_controller.rb
Created August 13, 2012 12:42 — forked from dblock/oauth_controller.rb
An updated OAuth2 controller for a Rails app (implies you have ClientApplication and AccessGrant)
class OauthController < ApplicationController
class ApiOAuthError < StandardError
attr_accessor :code, :description, :uri, :state
def initialize(code, description, uri = nil, state = nil)
@code = code
@description = description
@uri = uri