Skip to content

Instantly share code, notes, and snippets.

Avatar

Jak Charlton jakcharlton

View GitHub Profile
View eof-in-wrong-place.txt
map = <<EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
View eof-at-first-char.rb
# with EOF put at first character position
map = <<EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
View eof-indented.rb
# with EOF indented, using <<-
map = <<-EOF
function() {
this.tags.forEach(function(z) {emit(z,{count:1});});
}
EOF
View emptying_mongo.rb
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)
View embed_many.rb
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
View gemlist.rb
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
View controllerfactory.cs
public class ControllerFactory : IControllerFactory
{
readonly IWindsorContainer container;
public ControllerFactory() : this(((IContainerAccessor) HttpContext.Current.ApplicationInstance).Container)
{
}
public ControllerFactory(IWindsorContainer container)
{
@jakcharlton
jakcharlton / paginate.rb
Created Oct 16, 2010
will_devise and mongoid ... how to sort
View paginate.rb
@posts.paginate(:page => params[:page],
:per_page => 20,
:sort => [['added', :asc]])
View routefullstops.rb
match 'post/by_tag/:tag',
:to => 'posts#by_tag',
:as => 'posts_by_tag',
:tag => /[A-Za-z0-9\-_\.]*/
View dates.rb
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