Skip to content

Instantly share code, notes, and snippets.

View spohlenz's full-sized avatar

Sam Pohlenz spohlenz

View GitHub Profile
begin
require "sequel"
rescue LoadError
$stderr.puts "You don't have sequel installed in your application. Please add it to your Gemfile and run bundle install"
raise
end
Sequel::Model.plugin :active_model
module Trestle
@spohlenz
spohlenz / Trestle-CLA.txt
Last active July 28, 2017 01:45
Trestle Contributor License Agreement
## Trestle Contributor License Agreement
In order to clarify the intellectual property license granted with Contributions from any person or entity, the Trestle Project (the "Project") must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of the Project and its users; it does not change your rights to use your own Contributions for any other purpose.
The following terms are used throughout this agreement:
* You - the person or legal entity including its affiliates asked to accept this agreement. An affiliate is any entity that controls or is controlled by the legal entity, or is under common control with it.
* Project - is an umbrella term that refers to any and all projects within the Trestle organization.
* Contribution - any type of work that is submitted to a Project, including any modifications or additions to existing work.
* Sub
@spohlenz
spohlenz / gist:8346009
Created January 10, 2014 02:30
Resetting a Wheelhouse CMS admin password
$ rails console
Loading development environment (Rails 3.2.16)
> u = Wheelhouse::User.first
> u.password = u.password_confirmation = "newpassword"
> u.save
@spohlenz
spohlenz / devise.rb
Created October 13, 2012 01:14
Devise with MongoModel
# Replace relevant section in config/initializers/devise.rb
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/mongomodel'
def extract_extensions(filename)
extensions, *name = filename.split(".").reverse.slice_before { |f| f[" "] }.to_a
[name.flatten.reverse.join("."), extensions.reverse]
end
describe "#extract_extensions" do
specify { extract_extensions("some file name.with dots.html.markdown").should == ["some file name.with dots", ["html", "markdown"]]}
specify { extract_extensions("some file name with.dots.html.markdown").should == ["some file name with", ["dots", "html", "markdown"]]}
specify { extract_extensions("a b.c d.e").should == ["a b.c d", ["e"]] }
specify { extract_extensions("a.b c.a").should == ["a.b c", ["a"]] }
class Locale
def initialize(identifier)
@identifier = identifier.to_s
end
def to_mongo
@identifier
end
def self.from_mongo(mongo)
module Rack
class GoogleAnalytics
TRACKING_CODE = <<-EOCODE
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("{{ID}}");
def disabled
# no-op
end
<% disabled do %>
Everything within this block will not get executed or output.
<% raise 'Foobar' # Even Ruby code won't be run %>
<% end %>
@spohlenz
spohlenz / recipes_controller.rb
Created November 16, 2008 22:46
New controller pattern
class RecipesController < ApplicationController
...
def new
@recipe = flash[:recipe] || Recipe.new
end
def create
@recipe = Recipe.new(params[:recipe])