Skip to content

Instantly share code, notes, and snippets.

class AddSmallAndLargeThumbnailSizes < ActiveRecord::Migration
# added inline RefinerySetting class
class RefinerySetting < ActiveRecord::Base
serialize :value # stores into YAML format
def self.find_or_set(name, the_value, options={})
# if the database is not up to date yet then it won't know about scoping..
if self.column_names.include?('scoping')
options = {:scoping => nil}.merge(options)
find_or_create_by_name_and_scoping(:name => name.to_s, :value => the_value, :scoping => options[:scoping]).value
else
@nbrew
nbrew / YodaSpeak.rb
Created August 10, 2010 22:53 — forked from LeipeLeon/YodaSpeak.rb
YodaSpeak translator in ruby with added pivot words
# port of http://www.perlmonks.org/?node_id=162190
#
# Please refactor this if necessary
# leonb -at- beriedata -dot- nl
#
class String
def yoda
word = %w{is be will show do try are teach have look help see can learn has}.select { |word| self =~ /\b#{word}\b/ }[0]
if word
x = (self =~ /\b#{word}\b/) + word.size
# Method 1: add an after filter to set the variable, use it in the application layout
PageController.class_eval do
after_filter :set_header_quote, :only => [:show]
private :set_header_quote
def set_header_quote
@header_quote = 'Some header quote'
end
end
@nbrew
nbrew / add_indexes_for_models.rb
Created January 28, 2011 00:10
Bulk Update ActsAsIndexed Indexes for Specific Models
[Image,NewsItem,Page,Resource].each { |klass| klass.all.each {|e| e.add_to_index } }
@nbrew
nbrew / load_from_outline.rb
Created February 2, 2011 20:30
RefineryCMS: Create pages hierarchy from a simple text outline
#!/usr/local/bin/ruby
# Create/Load Pages from a text-based outline of titles.
# create this script in the root of your app
# otherwise, change the path to config/environment.
ENV["RAILS_ENV"] ||= 'development'
require File.dirname(__FILE__) + '/config/environment'
page_part_titles = Page.respond_to?(:default_page_parts) ? Page.default_page_parts : ['body','side_body']
@nbrew
nbrew / commit_assets.sh
Last active September 25, 2015 03:58
Commit an app's shared assets via svn and git.
#!/bin/bash
#
# Depending on your system (and your user's tendencies to
# upload files with non-ascii characters), you may wish to set the
# default locale language to en_US.UTF-8.
#
# set system-wide on a centos box (with a stock i18n file):
# sed -i -e 's/^#\(LANG="en_US.UTF-8"\)$/\1/' -e 's/^\(LANG="C"\)/#\1/' /etc/sysconfig/i18n
#
@nbrew
nbrew / red_cloth.rb
Created March 8, 2011 22:35
RedCloth initializer for rails app to enable no_span_caps by default
require 'redcloth/textile_doc'
module RedCloth
class TextileDoc
def initialize( string, restrictions = [:no_span_caps] )
restrictions.each { |r| method("#{r}=").call( true ) }
super( string )
end
end
end
@nbrew
nbrew / gitsco
Created March 16, 2011 18:20
Create a new directory, init a git svn repository.
#!/bin/bash
if [ $# -ne 1 ]; then
script=`basename $0`
echo "usage: ./${script} repository_name"
echo "Creates a new directory and initializes a new git svn repository."
exit 1
fi
repo=$1
dir=`basename ${repo}`
mkdir ${dir} && cd ${dir} && git svn init -s ${repo} && git svn fetch && if [ -e config/database.example.yml ]; then cp config/database.example.yml config/database.yml; fi && mate . && mate config/database.yml
@nbrew
nbrew / load.sh
Created March 22, 2011 00:53
Create and load a svn repository from a dump file.
#!/bin/bash
#
# load.sh
#
# script to create a repository and load a dumpfile
#
SVNADMIN=/usr/local/bin/svnadmin
REPO_DIR=/var/svn/repos
@nbrew
nbrew / new_ssl_cert.sh
Created April 1, 2011 06:22
Generate a new ssl key and CSR for Apache 2.x
function generate_new_ssl_cert() {
if [ -z $1 ]; then
echo ""
echo "usage: generate_new_ssl_cert example.com"
exit 1
fi
keydir=/etc/httpd/conf/ssl.key
csrdir=/etc/httpd/conf/ssl.csr
domain=${1}