Skip to content

Instantly share code, notes, and snippets.

View adstage-david's full-sized avatar

David Haslem adstage-david

View GitHub Profile
@adstage-david
adstage-david / 0_README.markdown
Last active February 7, 2018 16:20
Building an RFC compliant JSON-Patch with Rails 3 and Backbone

I recently got PATCH mostly working with Backbone and Rails 3, here's what I needed to do.

Sticking Points:

  1. [Rails] JSON Patch gem needs updated.
  2. [Rails] Routing verb for patch missing - I believe this is fixed in Rails 4, haven't investigated.
  3. [Rails] Need to parse the 'application/json-patch+json' content type in sort of a crazy way
  4. [Rails] Building a patch and applying it to an activerecord model is kind of a pain, ideally we'd have a ActiveModel#apply_patch(json_patch)
  5. [Backbone] Building a patch from a set of attributes is tricky - I've done the bare minimum using a loop over a hash to build add operations, which should probably cover a good chunk of cases for backbone. (I imagine most people aren't going to need the json-patch support for moving, copying or deleting keys generally.)
@adstage-david
adstage-david / reproduce_thread_error.rb
Created December 12, 2014 03:45
Reproduces thread error - run in context of rails app with sidekiq_unique_jobs installed
#!/usr/bin/env ruby
require 'benchmark'
require_relative '../config/environment'
threads = []
def connection(conn)
if conn
conn
# Call ActiveRecord::base.forbid_implicit_checkout_for_thread! from a thread, and if
# that thread later tries to access an active record connection without explicit checkout
# (#with_connection, or #checkout), an ImplicitConnectionForbiddenError will be raised.
module ActiveRecord
class Base
class << self
def forbid_implicit_checkout_for_thread!
Thread.current[:active_record_forbid_implicit_connections] = true
end
@adstage-david
adstage-david / build.boot
Created September 9, 2016 20:50
Example of Visual Regression test
(require '[visual-regression :as vr])
(deftask compare-screenshots
"Run visual regression specs over the devcards."
(let [tmp (core/tmp-dir!)]
(fn [next-task]
(fn [file-set]
(vr/compare-cards "vr")
(next-task file-set)))))
@adstage-david
adstage-david / page_helpers.clj
Created September 9, 2016 21:09
Smoke Test Examples
(ns page-helpers
"All of the following page helpers take a \"page\", which is a map with
key names for named elements tied to their CSS selectors.
Page is expected to always have keys:
- :page-name (string)
- :page-id (css selector string)
- :page-url (regex to match url)
Using this as the first argument allows us to use the while-on and
within-modal macros to fill in the page in repeated series of steps (they both
@adstage-david
adstage-david / blog.md
Last active September 9, 2016 21:25
Draft

How We Test Our Full-stack Clojure App

AdStage Report is a reporting product for advertisers built in the Untangled Framework and powered by the AdStage Platform API. It is still being actively developed, so code is being committed daily and we need to be sure we aren’t accidentally breaking features we’ve already shipped without a lot of tedious manual QA.

In our previous work with Ruby on Rails and Ember.js projects, we’ve relied heavily on testing to keep our quality up, so when we made the decision to experiment with a full-stack Clojure application in Report, one of the things we were worried about was how we’d be able to replace those tried and true testing solutions we had built up in an entirely foreign stack.

In some ways, a full-stack Clojure application feels like the wild west of web development and there don’t seem to be a lot of established best practices and prebuilt solutions. Luckily, the Untangled Framew

(do
(def
week-over-week-performance-summary
{:compare-to "previous_period",
:target-label nil,
:limit 10,
:response-type {:db/ident :data-source.response-type/table},
:filters [],
:fields ["spend" "clicks" "ctr"],
:layout-order nil,
@adstage-david
adstage-david / _README.md
Last active March 30, 2017 16:00
An Example Conversion Upload Script for a Google Sheet to upload conversions to AdStage

Example Custom Conversion Upload

This example script takes a Google Spreadsheet that is visible to anybody with the URL (example here: https://docs.google.com/spreadsheets/d/1D2_QWqMkELL2H-iSSi53VXJfGHoz9VXVqexRS4T1t4M/edit?usp=sharing), downloads it, converts to AdStage conversion format, then uploads to the AdStage custom conversion endpoint (as documented here: http://docs.adstageapi.apiary.io/#reference/0/custom-conversions/step-2.-post-data)

  1. To run this script, save this file as conversion_upload_script.rb
  2. Edit the variables
  • ADSTAGE_ORG must be set to your Organization number
@adstage-david
adstage-david / connector.js
Last active February 28, 2018 19:17
An Example Tableau + AdStage Connector (untested)
(function() {
// STEP 1 - CONFIGURE:
var adstageToken = "deadxxxxxbeef";
var adstageOrgId = 80;
// This makes it so AJAX calls are authenticated:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + adstageToken);