Skip to content

Instantly share code, notes, and snippets.

def permitted_params
product_params = params.require("product").permit(
:name, :raw_scores, :_type,
:articles, :article_ids, :raw_rating, :msrp, :slug,
:publish_on, :tags, :upc, :price_grabber_id,
:rubric_id, :brand_id, :archive_state, :is_scoring_baseline,
:scaled_scores, :amazon_asin, :amazon_is_related_product, award_ids: [],
attachment_ids: [], website_ids: [], keywords: [], types: [],
manufacturer_specs: [:id, :name, :value, :value_units, :value_type, :order, :options]
)
~ $ cat /usr/local/Cellar/elasticsearch/0.90.6/config/elasticsearch.yml
##################### ElasticSearch Configuration Example #####################
# This file contains an overview of various configuration settings,
# targeted at operations staff. Application developers should
# consult the guide at <http://elasticsearch.org/guide>.
#
# The installation procedure is covered at
# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
#
namespace :data_migrations do
desc "backport awarded_times field for existing products"
task awarded_times_backport: :environment do
product_ids = Award.all.map(&:product_ids).flatten.uniq
pb = ProgressBar.new(product_ids.count)
product_ids.each do |id|
pb.increment!
product = Product.where(id: id).first
if product
class Product
before_save :early_before
around_save :around
before_save :late_before
def early_before
puts "early before"
end
def around
### Keybase proof
I hereby claim:
* I am lukebergen on github.
* I am lukebergen (https://keybase.io/lukebergen) on keybase.
* I have a public key whose fingerprint is CA20 CB32 13AD B8ED 3A2A 5B28 4573 8E8C EDE6 2164
To claim this, I am signing this object:
@lukebergen
lukebergen / gist:10482714
Created April 11, 2014 16:37
tvi price filter replacement
# To replace tvi's need dropdown with the price dropdown, in categories/televisions/configatron.rb, replace this:
configatron.televisions.filters[:need] = {
resource: 'articles#show',
prompt: 'Find the perfect product for...',
options: [
{ name: 'Budget Buyers', query: { id: 'Budget-Buyers' }, url: '/buying-guides/budget-buyers' },
{ name: 'Sports Fans', query: { id: 'Sports-Fans' }, url: '/buying-guides/sports-fans' },
{ name: 'Movie Nights', query: { id: 'Movie-Nights' }, url: '/buying-guides/movie-nights' },
{ name: 'Perfect Picture', query: { id: 'Perfect-Picture' }, url: '/buying-guides/perfect-picture' },
@lukebergen
lukebergen / gist:cd16957aececc459a814
Created May 19, 2014 19:38
the-guide PG failures
Failures:
1) Api::V1::AuthorsController index returns a list of authors by website ids
Failure/Error: authors.should have(1).author
expected 1 author, got 0
# ./spec/controllers/api/v1/authors_controller_spec.rb:39:in `block (3 levels) in <top (required)>'
2) Api::V1::ProductsController types returns all of the product types available
Failure/Error: get :types
JSON::Schema::ValidationError:
@lukebergen
lukebergen / es_test.sh
Created October 13, 2014 21:27
Demonstration of ElasticSearch issue where function score fails if all records are filtered out
# Elasticsearch version: 1.3.4
curl -XDELETE localhost:9200/test > /dev/null 2>&1
curl -XPUT localhost:9200/test/test/1 -d '{
"name": "Finn",
"age": null
}' > /dev/null 2>&1
curl -XPUT localhost:9200/test/test/2 -d '{
def find_100s(digits, i=0)
if i == digits.length - 1
eval(digits) == 100 ? [digits] : []
else
[find_100s(digits[0..i] + "+" + digits[i+1..-1], i+2), find_100s(digits[0..i] + "-" + digits[i+1..-1], i+2), find_100s(digits, i+1)]
end
end
puts find_100s("123456789")
@lukebergen
lukebergen / gist:e5f1ca9a1e1b08a896c0
Created June 11, 2015 18:21
google shopping product_reviews schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified" vc:minVersion="1.0">
<xs:annotation>
<xs:documentation>
Google Product Review Feeds allow content providers to
provide product reviews to Google Shopping.
An XML file can be validated with this schema by running:
xmllint --schema product_reviews.xsd --noout file.xml