Skip to content

Instantly share code, notes, and snippets.

@lukebergen
lukebergen / gist:09b8b74e4c96f024f19168ee8f6b9215
Created October 10, 2017 21:45
Devil boss battle glitch?
When fighting the devil and he does the move where he stretches his
neck up and then comes slithering in from the side like a snake, he
seems to be able to hit you while he's retracting back. But only when
he comes in from the right.
This is me doing what I think is the correct thing to avoid his attack
when he comes in from the left:
https://gfycat.com/closedlateamazondolphin
This is me doing the same thing when he comes in from the right:
def paths(n, path=[], result=[])
if n == 0
result << path
elsif n > 0
[2, 3, 7].each {|score| paths(n - score, path + [score], result)}
end
result
end
puts paths(1).to_s
@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
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 / 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 '{
@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 / 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' },
### 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:
class Product
before_save :early_before
around_save :around
before_save :late_before
def early_before
puts "early before"
end
def around
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