Skip to content

Instantly share code, notes, and snippets.

module ActiveSupport
module Inflector
alias :old_foreign_key :foreign_key
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
old_foreign_key(class_name, false)
end
def tableize(class_name)
class_name
end
end
@carlhoerberg
carlhoerberg / gist:640479
Created October 22, 2010 12:41
Web.config lines to enable dynamic in NHaml views
<configSections>
<section name="nhaml" type="NHaml.Configuration.NHamlConfigurationSection, NHaml"/>
</configSections>
<nhaml templateCompiler="CSharp4" useTabs="true">
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</nhaml>
require 'rubygems'
require 'sinatra/base'
require 'haml'
require 'models'
require 'rack-flash'
require 'pony'
require 'mime/types'
class App < Sinatra::Base
enable :sessions
recipe Running jQuery recipe...
/usr/lib/ruby/1.8/open-uri.rb:174:in `open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError)
from /usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
from /usr/lib/ruby/1.8/open-uri.rb:518:in `open'
from /usr/lib/ruby/1.8/open-uri.rb:30:in `open'
from /usr/lib/ruby/gems/1.8/gems/thor-0.14.3/lib/thor/actions/file_manipulation.rb:55:in `get'
from http://railswizard.org/f866948c3a033b907ff4.rb:79:in `apply'
from /usr/lib/ruby/gems/1.8/gems/thor-0.14.3/lib/thor/actions.rb:167:in
`inside'
from /usr/lib/ruby/1.8/fileutils.rb:121:in `chdir'
@carlhoerberg
carlhoerberg / Rakefile
Created December 1, 2010 22:06
Resque + New Relic
task :environment do
DataMapper.setup(:default, ENV['DATABASE_URL'])
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY'])
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Pony.options = {
:via => :smtp,
:via_options => {
@carlhoerberg
carlhoerberg / AesCryptoProvider.cs
Created January 13, 2011 15:59
Implementation of an encrypted string user type
class AesCryptoProvider : ICryptoProvider
{
private string password;
public AesCryptoProvider(string password)
{
this.password = password;
}
public byte[] Encrypt(string inputText)
@carlhoerberg
carlhoerberg / EncryptedColumnInEntity.cs
Created January 13, 2011 16:14
Make the encryption explicit in the domain model
public class EncryptedColumnInEntity : Entity
{
protected virtual byte[] EncryptedText { get; set; }
/// <summary>
/// Decryptes the text stored in the database
/// </summary>
/// <exception cref="CryptographicException">Throws CryptographicException when the password isn't valid</exception>
/// <param name="password">The password which the text was encrypted with</param>
/// <returns>Decrypted text</returns>
@carlhoerberg
carlhoerberg / global.asax.cs
Created March 15, 2011 10:38
How to get precompiled mvc 3 site working in Mono 2.10
public class MonoWebFormViewEngine : WebFormViewEngine
{
protected override bool FileExists(ControllerContext controllerContext, string virtualPath)
{
return base.FileExists(controllerContext, virtualPath.Replace("~", ""));
}
}
public class MonoRazorViewEngine : RazorViewEngine
{
@carlhoerberg
carlhoerberg / Global.asax.cs
Created April 5, 2011 07:12
Replace log4net replacement for Elmah
protected void Application_Error(object sender, EventArgs e)
{
var error = Server.GetLastError();
var log = LogManager.GetLogger(GetType());
var msg = string.Format("\r\nPath: {0}\r\nMethod: {4}\r\nUser: {1}\r\nForm: {2}\r\nReferer: {3}",
Request.Url,
User.Identity.Name,
Request.Form,
Request.UrlReferrer,
Request.HttpMethod);
public class AutocompleteController : Controller
{
private readonly IRepository db;
public AutocompleteController(IRepository db)
{
this.db = db;
}
public JsonResult Users(string term)
{