Skip to content

Instantly share code, notes, and snippets.

View jeffrwells's full-sized avatar

Jeff Wells jeffrwells

  • Batch
  • New York, NY
View GitHub Profile
Vetdata::EndpointExtractor.each(:animal, :past_day) do |animal_data, installation|
animal_data = AnimalTransform.call(animal_data, installation)
AnimalChangesetCreator.call(animal_data)
end
class AnimalTransform
def self.call(animal_data, installation)
{
@jeffrwells
jeffrwells / refresh.js
Created March 10, 2015 18:48
Dataclip backup
function refreshDataClip() {
var sheet = SpreadsheetApp.getActiveSheet();
var urlCell = sheet.getRange('A1');
var cellFormula = urlCell.getFormula();
var documentProperties = PropertiesService.getDocumentProperties();
Authentication: pass your api token in the 'X-ACCESS-TOKEN' request header, or in the 'api_token' parameter
Create a user
POST
onboardiq.com/api/v1/applicants
Required attributes: [name, email, phone]
Email must be valid and unique
class Api::V1::BaseController < ApplicationController
respond_to :json
before_action :authenticate! #make this the default, then you could use skip_before_action on an action you don't need it
def authenticate!
load_account || access_denied
end
def access_denied
class AccountsController < ApplicationController
layout 'admin'
inherit_resources
#TODO: even if admin, it denies access.
load_and_authorize_resource :except => [:dashboard, :new, :create, :plans, :canceled, :thanks]
before_filter :authenticate_user!, :except => [ :new, :create, :plans, :canceled, :thanks]
before_filter :authorized?, :except => [ :new, :create, :plans, :canceled, :thanks]
before_filter :build_user, :only => [:new, :create]
before_filter :load_billing, :only => [ :billing, :paypal ]
@jeffrwells
jeffrwells / gist:8968610
Last active August 29, 2015 13:56
recommendations based on language, time, project
######## This implementation takes one recent, one from same project, one from same language, but code is awful ########
recommended = []
user = post.user
posts = user.posts.published.ordered
#project
recommended += posts.where(repository_id: post.repository_id).not_in(recommended.map(&:id) + [post.id])
@jeffrwells
jeffrwells / question.rb
Last active December 27, 2015 09:49
Use a postgres string[] column for both singular entries and arrays. If the question type is a MULTISELECT, then the attribute will act like an array, but if not, it acts like a String. However, this particular String does not respond to <<, so that it will throw errors if you try to use it. This way, if the developer is has an array, and trying…
class CreateQuizzes < ActiveRecord::Migration
def change
create_table :quiz_questions do |t|
t.integer :quiz_id
t.string :format, :default => 'MultiChoice' #MultiChoice, MultiSelect, or Field
t.string :answer, array: true, default: []
t.string :options, array: true, default: []
t.timestamps
end
end
@jeffrwells
jeffrwells / gist:7228297
Created October 30, 2013 07:13
User model with two event models.
class User < ActiveRecord::Base
has_many :github_events
has_many :twitter_events
def events
#help: github + twitter
end
end