Skip to content

Instantly share code, notes, and snippets.

View aamax's full-sized avatar

Allen Maxwell aamax

  • aaMaxWorks Engineering, LLC
  • Draper, Utah USA
View GitHub Profile
@aamax
aamax / html content
Created April 16, 2017 22:16
raffle selection spinner for RubyHACK....
<div class="well">
<h1 id="selected_winner">Spin To Select A Winner!</h1>
<br/>
<div id="planeMachine" style="overflow: hidden; height: 70px;" class="" >
<div class="slotMachineContainer" style="transition: 0.9s ease-out; transform: matrix(1, 0, 0, 1, 0, -240);">
<% @raffle_entries.each do |re| %>
<div class="text-center">
<h1 id="panel1"><%= "#{re[:fname]} #{re[:lname]}" %></h1>
</div>
@aamax
aamax / models, associations and tests
Created May 14, 2016 07:30
AR association tests not passing
class User < ActiveRecord::Base
has_many :lead_offers
has_many :leads, through: :lead_offers
end
class Lead < ActiveRecord::Base
has_many :lead_offers, dependent: :destroy
has_many :users, :through => :lead_offer
end
$ gem list
*** LOCAL GEMS ***
actionmailer (4.2.4)
actionpack (4.2.4)
actionview (4.2.4)
activejob (4.2.4)
activemodel (4.2.4)
activerecord (4.2.4)
@aamax
aamax / application.rb
Last active November 10, 2015 15:13
weird datetime issues in rails
config.time_zone = "Pacific Time (US & Canada)"
config.active_record.default_timezone = "Pacific Time (US & Canada)"
@aamax
aamax / curls
Last active August 29, 2015 14:25
curl -i -H "Accept: application/json" -X POST -H "Content-Type: application/json" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
I've also tried changing the json to html
curl -i -H "Accept: application/html" -X POST -H "Content-Type: application/json" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
curl -i -H "Accept: application/html" -X POST -H "Content-Type: application/html" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
curl -i -H "Accept: application/json" -X POST -H "Content-Type: application/html" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
@aamax
aamax / gist:0556b89c1537b45354d4
Created July 14, 2015 17:09
how to do JSON return in this format?
I have a model that looks like:
# == Schema Information
#
# Table name: vendors
#
# id :integer not null, primary key
# company_name :string
# category :string
#
I'm trying to test the controller - to make sure that a logged in user who is not an admin user, cannot look at another users show page, and that they can look at their own.
I'm beginning to suspect that this testing is really only relevant inside the policy tests and that I have to assume that the controllers are following the policies as described.
The system uses:
Rails 4.2.1
Minitest
Devise
Pundit
Rolify
@aamax
aamax / towers of hanoi code
Created October 6, 2014 13:51
Towers of Hanoi solution in ruby
require 'minitest/spec'
require 'minitest/autorun'
describe 'Game' do
it 'should have 3 pegs' do
game = Game.new
game.pegs.count.must_equal 3
end
it 'should have 3 discs by default' do
@aamax
aamax / solution_aamax_dave_hacket
Created September 24, 2014 20:41
URUG 20140923 meeting results: CSV file parsing
# the code is unfinished as of yet, this is as far as we got during the meeting
class Parser
def initialize filename, delimiter=","
@fhandle = File.open(filename, 'r')
@delim = delimiter
@header = []
@arr_val = []
line_str = @fhandle.readline
@header = parse_row(line_str)
end
@aamax
aamax / model and controller
Last active December 28, 2015 23:08
trying to add a field to an activerecord model to set some values at run time.
# ----------------------
class MyObj < ActiveRecord::Base
attr_accessor :i_can_select
end
# ----------------------
class MyController < ApplicationController
def index
@list = MyObj.all