This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory.define :application do |factory| | |
factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def following_by_type(followable_type, options={}) | |
follows = followable_type.constantize. | |
includes(:followings). | |
where( | |
"follows.follower_id = ? AND follows.follower_type = ? AND follows.followable_type = ? AND blocked = ?", | |
self.id, parent_class_name(self), followable_type, false | |
) | |
if options.has_key?(:limit) | |
return follows.limit(options[:limit]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FollowsController < ApplicationController | |
def create | |
@followable = find_followable | |
@follower = find_follower | |
@follower.follow(@followable) | |
redirect_to (@followable) | |
end | |
def destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
inputs = [:path, :hash, :file, :tempfile, :stringio] | |
outputs = [:path, :file, :tempfile, :stringio, :nil] | |
def get_input(input_type, file_name = 'fields.pdf') | |
case input_type | |
when :path | |
path_to_pdf(file_name) | |
when :hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ProductsController.class_eval do | |
respond_to :html, :js | |
def show | |
product_source = Product.find_by_permalink!(params[:id]) | |
@product = ProductDecorator.new(product_source) | |
return unless @product | |
if params[:option_values] | |
option_values_ids = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
class Walkscore | |
include HTTParty | |
default_params :format => 'json' | |
attr_accessor :api_key, :property | |
def initialize(api_key, property) | |
self.api_key = api_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"bool": { | |
"must_not": [ | |
{"term": {"topic_ids": "NTfaluJAzhU6ajVN"}}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TO_FOLDER=/something | |
# FROM=/your-es-installation | |
DATE=`date +%Y-%m-%d_%H-%M` | |
TO=$TO_FOLDER/$DATE/ | |
echo "rsync from $FROM to $TO" | |
# the first times rsync can take a bit long - do not disable flusing | |
rsync -a $FROM $TO | |
# now disable flushing and do one manual flushing |