Skip to content

Instantly share code, notes, and snippets.

View rkellermeyer's full-sized avatar

Richard Kellermeyer rkellermeyer

  • USA
View GitHub Profile
@rkellermeyer
rkellermeyer / user.rb
Created February 12, 2012 19:22
Using Redis to log categories that a user can follow
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :first_name, :last_name, :zipcode
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
@rkellermeyer
rkellermeyer / background_nested.html
Created August 4, 2012 20:59
Give nested div same color as background
<!DOCTYPE HTML>
<html lang="ru-RU">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body, .nested {
background: blue;
}
.container, .nested {
@rkellermeyer
rkellermeyer / _form.html.haml
Created August 16, 2012 15:55
can't dump anonymous class #<Class:0x007fe4c7d29228>
= semantic_form_for [:admin, @sale], html: { :class => "filter_form" } do |f|
= select "sale_", "id", Sale.all.collect{ |s| [s.title + " " + s.start_date.to_s, s.id] }, {include_blank: true}, class: "sale_dropdown"
= f.inputs "Sale Information" do
= f.input :sales_merchandiser_id, :as => :hidden, :value => proc{current_user.id}
= f.input :category_id, as: :hidden
= f.input :title
= f.input :featured_image, as: :file, label: "Sale Image"
= content_tag :li, class: "field_toggle" do
%span.show_overwrite_fields Overwrite Versions
%span.hide_overwrite_fields Cancel Override
@rkellermeyer
rkellermeyer / routes.rb
Created September 5, 2012 22:27
No Ransack::Search object was provided to search_form_for! when using ActiveAdmin
MyAppName::Application.routes.draw do
# ...
namespace :admin do
resources :sales do
resources :consignment_items do
collection { post :search_items, to: 'sales#search_consignment_items' }
end
end
end
# ...
@rkellermeyer
rkellermeyer / errors.txt
Created September 19, 2012 01:00
Form Nested on non-Modal view
Routing Error
No route matches {:action=>"new", :controller=>"messages"}
Try running rake routes for more information on available routes.
@rkellermeyer
rkellermeyer / application.html.haml
Created October 6, 2012 16:41
"can't dup NilClass" type error in search
# ...
= semantic_form_for users_path, :method => 'get', :id => "users_search" do |f|
= f.input :search, params[:search]
= f.submit_tag
#...
@rkellermeyer
rkellermeyer / auth_net_samples.php
Created November 16, 2012 20:44
Auth.net PHP samples
<?php
require_once '../anet_php_sdk/AuthorizeNet.php'; // The SDK
$url = "http://YOURSITE.tld/post_result.php";
$api_login_id = '######';
$transaction_key = '#############';
$md5_setting = '######'; // Your MD5 Setting
$amount = "5.99";
AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);
define("AUTHORIZENET_API_LOGIN_ID", $api_login_id);
@rkellermeyer
rkellermeyer / pdfr.rb
Created January 10, 2013 21:06
PDF'r
require 'prawn'
Prawn::Document.generate("testing.pdf") do
Dir.foreach(".") do |f|
text "#{f}"
content = File.foreach(f).map(&:line) unless f == "." || f == ".."
text "#{content}"
end
end
@rkellermeyer
rkellermeyer / spec_results.txt
Created August 6, 2013 13:36
Scope that only returns users who are 21 or older
Failures:
1) User scopes .adult_purchases_enabled does not return users who are not at least 21 years old
Failure/Error: User.adult_purchases_enabled.should_not include(subject)
expected [#<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895, longitude: -73.6389, active: false>] not to include #<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06 00:00:00", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895272, longitude: -73.6389038, active: false>
Diff:
@@ -1,2 +1,2 @@
-[#<User id: 338, f
@rkellermeyer
rkellermeyer / user.rb
Last active December 20, 2015 16:59
Can you build a scope by model method value? (Edited showing non-working scope vs. working scope)
class User < ActiveRecord::Base
# ...
# Old scope: scope :adult_purchases_enabled, -> { where(self.age >= 21) }
# Working scope:
scope :adult_purchases_enabled, -> { where('birth_date <= ?', Time.current.advance(years: -21)) }
# ...
# Public Methods
def age
(Time.now.utc().to_s(:number).to_i - self.birth_date.to_time.utc().to_s(:number).to_i)/10e9.to_i