Skip to content

Instantly share code, notes, and snippets.

Josef Richter josefrichter

Block or report user

Report or block josefrichter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:393861
for(i = 0; i < parent_names.length; i++) {
if(parent_ids[i]) {
content = content.replace(
new RegExp('(\[' + parent_names[i] + '\])\[.+?\]', 'g'),
'$1[' + parent_ids[i] + ']'
var regexp_string = '\\[' + parent_names[i] + '\\]\\[.+?\\]';
View gist:397715
@event = => params[:title], :start => params[:start], :end => params[:end])
View gist:437876
<% unless current_user.address.nil? %>
<%= %><br/>
<%= %><br/>
<%= current_user.address.street %><br/>
<%= %><br/>
<%= current_user.address.code %><br/>
<% end %>
View gist:445115
<p id="notice"><%= notice %></p>
<%= @document.title %>
<%= @document.body %>
View gist:448789
class Suggestion
include Mongoid::Document
field :title, :type => String
field :body, :type => String
field :slug, :type => String
embeds_many :votes
embeds_many :features
#index :votes_difference
View gist:449638
def create
@suggestion =[:suggestion])
# create slug - TODO move somewhere
@suggestion.slug = params[:suggestion][:title].parameterize
# adjust slug if not unique
while !@suggestion.valid? && @suggestion.errors["slug"].include?("is already taken")
if @suggestion.slug[/-\d+$/].nil? # does the slug contain "-123" at the end?
@suggestion.slug<<"-2" # if not, assuming it's first duplicate and add "-2"
View gist:451417
# taken from
require 'activerecord'
rescue LoadError
require 'active_record'
class ActiveRecord::Base
module PickleAdapter
View feature.rb
class Feature
include Mongoid::Document
field :body, :type => String
embedded_in :suggestion, :inverse_of => :features
has_many_related :votes, :as => :votable
View blueprints.rb
require 'machinist/mongoid'
require 'sham'
require 'faker'
Sham.define do
title { Faker::Lorem.words(5).join(' ') }
body { Faker::Lorem.paragraphs(3).join("\n\n") }
View mongoid.rb
# MongoID adapter for Pickle
require 'mongoid'
class Mongoid
module PickleAdapter
include Pickle::Adapter::Base
# Do not consider these to be part of the class list
def self.except_classes
You can’t perform that action at this time.