Skip to content

Instantly share code, notes, and snippets.

@victorwhy
victorwhy / shopify_query.txt
Last active January 21, 2020 18:34
Shopify Graph QL query to be the "products" JAPI endpoint
{
products(first: 3) {
edges {
node {
id
...variantData
}
}
}
}
@victorwhy
victorwhy / gist:5e6f8c92ddf5357b100d
Last active August 29, 2015 14:06
__proto__ vs prototype

The proto property of Object.prototype is an accessor property (a getter function and a setter function) that exposes the internal [[Prototype]] (either an object or null) of the object through which it is accessed.

FYI MDN says proto is being deprecated - use Object.getPrototypeOf and Object.setPrototypeOf (setter not recommended to use) instead.

Basically, when a new instance of a constructor is created, it's proto is the same as the constructor's prototype.

// Declare a function to be used as a constructor
function Employee() {
    /* initialise instance */
@victorwhy
victorwhy / gist:45bb5637cd3e7e879ace
Last active February 21, 2023 11:17
How Sinatra routes PUT/PATCH and DELETE

HTML and Sinatra really only support the GET and the POST methods. In order to be able to use the PUT and DELETE methods in Sinatra, you kind of have to "trick" the form to go to the right place. Then you can name the routes the proper way - otherwise you can only really work with GET and POST.

I used the Craiglist Jr challenge for some examples. Let's look at a quick example of a POST form/method/route- in this case, we're creating a new Craigslist article:

POST form and corresponding route:

<form action="/article/new" method="post">
  --------------------------------
  YOUR FORM FIELDS HERE

Rails ActiveRecord (association) - Cheatsheet

http://guides.rubyonrails.org/association_basics.html

Types of associations

  • belongs_to : TABLE_NAME
  • has_one : TABLE_NAME [:through => :TABLE_NAME]
  • has_many : TABLE_NAME [:through => :TABLE_NAME]
  • has_and_belongs_to_many : TABLE_NAME [:join_table => :TABLE_NAME]