Skip to content

Instantly share code, notes, and snippets.

View cedricdekimpe's full-sized avatar

Cédric Dekimpe cedricdekimpe

View GitHub Profile
@cedricdekimpe
cedricdekimpe / add_full_text_to_locomotive.rb
Created October 24, 2013 09:06
LocomotiveCMS search : config/initializer/add_full_text_to_locomotive.rb
#encoding: utf-8
::STOP_WORDS = Hash[[
"alors", "au", "aucuns", "aussi", "autre", "avant", "avec", "avoir",
"bon", "car", "ce", "cela", "ces", "ceux", "chaque", "ci", "comme", "comment", "dans", "des", "du",
"dedans", "dehors", "depuis", "deux", "devrait", "doit", "donc", "dos", "droite", "début", "elle",
"elles", "en", "encore", "essai", "est", "et", "eu", "fait", "faites", "fois", "font",
"force", "haut", "hors", "ici", "il", "ils", "je juste", "la", "le", "les", "leur", "là", "ma", "maintenant",
"mais", "mes", "mine", "moins", "mon", "mot", "même", "ni", "nommés", "notre", "nous", "nouveaux", "ou", "où",
"par", "parce", "parole", "pas", "personnes", "peut", "peu", "pièce", "plupart", "pour", "pourquoi", "quand", "que",
@cedricdekimpe
cedricdekimpe / Gemfile
Created October 24, 2013 09:05
Gemfile for LocomotiveCMS search
gem 'mongoid_fulltext', '0.6.1'
@cedricdekimpe
cedricdekimpe / search_controller.rb
Created October 24, 2013 09:05
SearchController for LocomotiveCMS
class SearchController < ApplicationController
include Locomotive::Routing::SiteDispatcher
include Locomotive::Render
def index
@page = Locomotive::Page.where(:handle => 'search-results').first
results = Locomotive::ContentEntry.fulltext_search(params[:search])
@drops_results = Liquid::Drops::ResultsDrop.new(results)
render_locomotive_page @page, { "search_results" => @drops_results }
end
@cedricdekimpe
cedricdekimpe / pagination.liquid
Created September 13, 2013 14:23
Custom pagination with LocomotiveCMS
<nav class="pagination">
<ul>
{% if paginate.current_page > 1 %}
<li>
<a href="?page=1">first</a>
</li>
{% endif %}
{% if paginate.previous_page %}
<li>
<a href="?page={{paginate.previous_page}}" rel="prev">prev.</a>
class Industry < ActiveResource::Base
self.site = "http://my.site.com"
self.prefix = "prefix/api/"
end

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

#!/bin/bash
bucket="BUCKETNAME"
expireweeks=3
databases=`mysql -e "SHOW DATABASES;" | tr -d "| " | grep -v "\(Database\|information_schema\|mysql\)"`
datestamp=`date +"%m-%d-%y"`
timestamp=`date +"%H%M%S"`
for db in $databases; do
(function(window, undefined) { "use strict";
var jQuery = window.alohaQuery || window.jQuery,
$ = jQuery, Aloha = window.Aloha;
Aloha.MetaView = new (Aloha.Plugin.extend({
_constructor: function(){
this._super('metaview');
},
/*** Configure the available languages*/
# Load the rails application
require File.expand_path('../application', __FILE__)
require File.expand_path('../app_config.rb', __FILE__)
#config.active_record.default_timezone = "UTC"
#config.time_zone = "UTC"
ActionView::Base.field_error_proc = proc { |input, instance| input }
# source: http://codesnipr.com/snippet/1105/Rails-3-Removing-field-with-errors-division
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}