Skip to content

Instantly share code, notes, and snippets.

@HoyaBoya
HoyaBoya / .json
Last active March 26, 2024 21:22
crmls_lim_create_example
{
"acknowledgedWarnings": [
"string"
],
"listing": {
"core": {
"uid": "string",
"cumulativeDaysOnMarket": 0,
"daysOnMarket": 0,
"previousStandardStatus": "string",
module Middleware
class VersionEndpoint
def initialize(app)
@app = app
end
def call(env)
# Return the latest git-sha in ENV if the request is exactly the version endpoint.
if env['PATH_INFO'] == '/version'
if version = source_version
@HoyaBoya
HoyaBoya / reverse_linked_list.rb
Created April 8, 2014 14:37
Reverse a Singley Linked List
# PROBLEM:
# Given a singley linked list, reverse the list.
#
# SOLUTION:
# Nothing to tricky other to keep track of all the pointers when iterating through.
# Basic object to represent a linked list.
class Node
attr_accessor :next
attr_accessor :value
@HoyaBoya
HoyaBoya / x.rb
Last active August 29, 2015 13:58
Print "helloworld" with the following if/else statement.
# PROBLEM
# Find an implementation of "x" that will force the code below to print "helloworld".
# SOLUTION
# This doesn't work with threads forked to return true/false. The trick is to just have x do both.
def x
print "hello"
false
end
##
# This is spree 2-1-stable specific logic to re-apply a promotion code. It will not work for 2-2-stable because promotions are being revamped.
# https://github.com/spree/spree/issues/4398
#
def reapply_coupon_codes
codes = []
# Go through the adjustments to find promotions that are not eligible
adjustments.each do |a|
if a.eligible == false && a.originator.respond_to?(:promotion) && a.originator.promotion.code
source 'https://rubygems.org'
#############################
# Environment-agnostic gems #
#############################
gem 'rails', '4.0.0'
gem 'rack-cors', :require => 'rack/cors' # cross-domain request support for rack
gem 'pg' # postgres database client
gem 'sass-rails', '~> 4.0.0' # Use SCSS for stylesheets
def product_scope
variants_associations = [{ option_values: :option_type }, {images_for_variant: {variant_images: :image}}, :default_price, :prices, :images, { variant_description: :description }]
if current_api_user.has_spree_role?("admin")
scope = Spree::Product.with_deleted.accessible_by(current_ability, :read)
.includes(:product_properties, {:option_types => :option_values}, variants: variants_associations, master: variants_associations)
unless params[:show_deleted]
scope = scope.not_deleted
end
else
Started GET "/api/products/the-skinny" for 127.0.0.1 at 2014-02-03 12:17:41 -0500
Spree::User Load (0.6ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."id" IS NULL LIMIT 1
Token sign-in failed with nil
Spree::Product Load (1.1ms) SELECT "spree_products".* FROM "spree_products" INNER JOIN "spree_variants" ON "spree_variants"."product_id" = "spree_products"."id" AND "spree_variants"."is_master" = 't' INNER JOIN "spree_prices" ON "spree_prices"."variant_id" = "spree_variants"."id" WHERE "spree_products"."deleted_at" IS NULL AND "spree_products"."permalink" = 'the-skinny' AND ("spree_products".deleted_at IS NULL or "spree_products".deleted_at >= '2014-02-03 17:17:41.434945') AND ("spree_products".available_on <= '2014-02-03 17:17:41.435128') LIMIT 1
Spree::ProductProperty Load (0.5ms) SELECT "spree_product_properties".* FROM "spree_product_properties" WHERE "spree_product_properties"."product_id" IN (5) ORDER BY spree_product_properties.position
Spree::ProductOptionType Load (0.3ms)
Started GET "/api/products/awesome-pants" for 127.0.0.1 at 2014-02-03 09:27:15 -0500
Spree::User Load (0.6ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."spree_api_key" = '6ba5d874b7c63fe8a74bb44ad658f3052a4a1148bd83a5f3' LIMIT 1
(0.5ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = $1 AND "spree_roles"."name" = 'admin' [["user_id", 1]]
CACHE (0.0ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = $1 AND "spree_roles"."name" = 'admin' [["user_id", 1]]
Spree::Product Load (0.6ms) SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."slug" = 'awesome-pants' AND ("spree_products".deleted_at IS NULL or "spree_products".deleted_at >= '2014-02-03 14:27:15.814917') ORDER BY "spree_products"."id" ASC LIMIT 1
Spree::ProductProperty Load (0.4ms) S
Started GET "/api/products/awesome-pants" for 127.0.0.1 at 2014-02-01 17:07:16 -0500
Spree::User Load (1.0ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."spree_api_key" = '6ba5d874b7c63fe8a74bb44ad658f3052a4a1148bd83a5f3' LIMIT 1
(1.1ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = $1 AND "spree_roles"."name" = 'admin' [["user_id", 1]]
CACHE (0.0ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = $1 AND "spree_roles"."name" = 'admin' [["user_id", 1]]
Spree::Product Load (0.6ms) SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."permalink" = 'awesome-pants' AND ("spree_products".deleted_at IS NULL or "spree_products".deleted_at >= '2014-02-01 22:07:16.271778') LIMIT 1
Spree::Variant Load (0.4ms) SELECT "spree_variants".* FROM "spree_v