Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
map = <<EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
# with EOF put at first character position
map = <<EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
# with EOF indented, using <<-
map = <<-EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
puts 'Empty the MongoDB database, exclude System stuff'
Mongoid.master.collections.select do |collection|
include = collection.name !~ /system/
puts 'Dropping ' + collection.name if include
include
end.each(&:drop)
class UserAccountsController < ApplicationController
def signin
auth = request.env['rack.auth']
user_for_provider_and_uid = UserAccount.find_by_provider_and_uid(auth['provider'], auth['uid']).first()
new_auth = Authorization.new(:user_id => auth['user_id'], :provider => auth['provider'], :uid => auth['uid'], :user_info => auth['user_info'], :credentials => auth['credentials'])
if user_for_provider_and_uid.nil?
user = signed_in? ? self.current_user : UserAccount.new(:name => auth['user_info']['name'])
user.authorizations << new_auth
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem "mongoid", "2.0.0.beta.17"
gem "bson_ext", "1.0.4"
gem 'omniauth'
$heroku = ENV['USER'] ? !! ENV['USER'].match(/^repo\d+/) : ENV.any?{|key, _| key.match(/^HEROKU_/)}
unless $heroku
public class ControllerFactory : IControllerFactory
{
readonly IWindsorContainer container;
public ControllerFactory() : this(((IContainerAccessor) HttpContext.Current.ApplicationInstance).Container)
{
}
public ControllerFactory(IWindsorContainer container)
{
@jakcharlton
jakcharlton / paginate.rb
Created October 16, 2010 21:28
will_devise and mongoid ... how to sort
@posts.paginate(:page => params[:page],
:per_page => 20,
:sort => [['added', :asc]])
match 'post/by_tag/:tag',
:to => 'posts#by_tag',
:as => 'posts_by_tag',
:tag => /[A-Za-z0-9\-_\.]*/
if last_vote_date.nil? || last_vote_date.utc < 1.day.ago
self.last_vote_date = Time.now
self.votes_per_day = 1
else
self.votes_per_day += 1
end
if self.votes_per_day <= 10
self.reputation += 1
end