Skip to content

Instantly share code, notes, and snippets.

View rystraum's full-sized avatar

Rystraum Gamonez rystraum

  • Loudcloud Inc. / Intelimina Systems Inc.
  • Philippines
View GitHub Profile
@rystraum
rystraum / app-graphql-mutations-upload_avatar.rb
Created June 30, 2021 22:12
File Upload using Rails ActiveStorage, GraphQL
class Mutations::UploadAvatar < Mutations::BaseMutation
null true
field :success, Boolean, null: false
field :errors, [String], null: true
field :thing, Types::ThingType, null: true
# query:
# mutation requestResetPassword($input: UploadAvatarInput!) {
# uploadAvatar(input:$input) {
# success

Terminologies:

  • Mbox - referenced as "Location" in Target's web interface. You can think of this as the div that will house the Experience's Offer.
  • Offer - the actual content that will go in an Mbox. This can be plain text, HTML or Javascript. mbox.js does an JS.append of the entire content. at.js insertion is based on how React does the insertion upon render.

Notes:

  • Use at.js if using this under React.

As far as I can tell, Target's AB testing model (using React) is as follows:

  1. Load the component
  2. The first time an `` component is encountered, send an AJAX request to Adobe which retrieves the Offer.
# views/items/index.html.erb
<dl>
<% @items.each do |item| %>
<dt><%= item.name %><dt>
<dd><%= item.price %></dd>
<% end %>
</dl>
# controllers/items_controller.rb
# params
{"utf8"=>"✓",
"authenticity_token"=>"lHpn6sCR208J+vxmdoM1h5lbni8AMKZz2NrcOVcBGFo=",
"response"=>
{"answers_attributes"=>
{"0"=>{"question_id"=>"13", "value"=>"E"},
"1"=>{"question_id"=>"14", "value"=>"E"},
"2"=>{"question_id"=>"15", "value"=>"ewrq"},
"3"=>{"question_id"=>"16", "value"=>""},
"4"=>{"question_id"=>"17", "value"=>""},
require "test_helper"
describe FormsController, "#show" do
extend CitizenHelper
def setup
Form.delete_all
Question.delete_all
@form = create :active_form
end
@rystraum
rystraum / gist:5586611
Created May 15, 2013 19:24
Ember polymorphic associations
# doctor.rb
class Doctor < ActiveRecord::Base
has_one :user, as: :profile
has_and_belongs_to_many :patients
end
# patient.rb
class Patient < ActiveRecord::Base
has_one :user, as: :profile
has_and_belongs_to_many :doctors
Full disclosure: This is my understanding on how Ember works. Feel free to correct me on points where I'm wrong.
How I understand it is that Ember starts with the route (the actual url on the address bar).
From the url in the address bar, it tries to match a route from your App.Router.
Once a route is matched, it calls the corresponding Route class (extending Em.Route), here you set up the model.
This route is paired with a controller (even if you don't specify one, it's matched with a generic controller) and renders a template.
In concrete terms, if you have the following Route map:
App.Router.map(function(){
@rystraum
rystraum / affiliateadmin.php
Created September 27, 2012 08:13
Itemized list of Referrals
<?php
// Administration side of the affiliate system
class affiliateadmin {
var $build = 6;
var $db;
var $mylocation = "";
@rystraum
rystraum / erepublik.user.js
Created June 6, 2012 18:47
eRepublik market scraper
// ==UserScript==
// @name Erepublik
// @namespace erep
// @include http://economy.erepublik.com/en/*
// @version 1
// ==/UserScript==
var console = unsafeWindow.console;
var url = window.location;