Skip to content

Instantly share code, notes, and snippets.

View Ch4s3's full-sized avatar

Chase Gilliam Ch4s3

View GitHub Profile
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
FactoryGirl.define do
factory :user, class: "User::Doctor" do
sequence(:email) { |n| "user#{User.last.id + 1}@avhana.com" }
sequence(:username) { |n| "user#{User.last.id + 1}" }
password "password"
organization
emr "allscripts"
end
factory :root_user, parent: :user, class: "User::Root" do
require 'spec_helper'
describe User do
it { should validate_presence_of(:password) }
it { should belong_to :organization }
it { should ensure_inclusion_of(:type).in_array(User.descendants.map(&:name)) }
describe "factory" do
subject { FactoryGirl.build :user }
before { FactoryGirl.create :user }
ActiveRecord::SchemaMigration Load (2.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
/Users/chase/.rvm/gems/jruby-head/gems/activemodel-4.1.9/lib/active_model/validations/confirmation.rb:19: warning: private attribute?
User Load (4.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
method=GET path=/ format=html controller=dashboard action=index status=500 error='ActionView::Template::Error:bad value for range
(in /Users/chase/code/athene/app/assets/stylesheets/application.scss)' duration=2002.00
ArgumentError - bad value for range
(in /Users/chase/code/athene/app/assets/stylesheets/application.scss):
sass (3.4.13) lib/sass/scss/parser.rb:1192:in `tok'
sass (3.4.13) lib/sass/scss/parser.rb:124:in `s'

To deploy from Codeship on Aptible, we recommend the following approach:

  1. Create a “Robots” role in your Aptible organization, and grant it “Read” and “Manage” permissions on your production account.
  2. Invite a new deploy user to this Robots role. It needs to have a real email address, but can be something like deploy@yourdomain.com.
  3. Accept the invitation for deploy@yourdomain.com, activate the account.
  4. Get the Codeship SSH public key from your project's general settings tab and add it to the SSH keys for the Robot user from step 3.
  5. Add a custom deploy step, following Codeship’s instructions. It should look something like:

git push git@beta.aptible.com:${APTIBLE_APP}.git ${CI_COMMIT_ID}:master

@Ch4s3
Ch4s3 / vcr_config_and_example.rb
Last active September 11, 2015 16:01
Rspec, VCR custom request matchers to ignore nondeterministic params
#In your rails_helper.rb
some_api_matcher = VCR.request_matchers.uri_without_param(:token)
VCR.configure do |config|
# use the following option to debug VCR
# config.debug_logger = STDOUT
config.cassette_library_dir = "spec/cassettes"
config.hook_into :webmock, :typhoeus, :faraday
config.default_cassette_options = { record: :new_episodes }

Ruby on Rails is a great application framework with a lot of advantages that are well documented elsewhere Occasionally, however, you may find yourself looking for a few tools just outside of the Rails toolbox. In some of those cases, JRuby can provide some additional options without giving up the expressiveness of Ruby or the fast prototyping and sane conventions of Rails.

Reasons to use JRuby

  • Real Concurrency
  • Java Interoperability
  • Large gains in speed (once the JVM has warmed up)
  • Excellent tooling around the JVM

These are all great reasons, especially concurrency and gains in speed. With a bit of discipline and a little trail and error, the average Rails developer can realize these benefits without giving up everything the ecosystem affords. Real threads used with application servers like Puma can allow more simultaneous connections to a single server instance, which can save money and resources over time. For the purposes of this multi-part tutorial w

if RUBY_PLATFORM == "java" # Allows the application to work with other Rubies if not JRuby
require "java"
java_import "java.lang.ClassNotFoundException"
begin
security_class = java.lang.Class.for_name("javax.crypto.JceSecurity")
restricted_field = security_class.get_declared_field("isRestricted")
restricted_field.accessible = true
restricted_field.set nil, false
rescue ClassNotFoundException => e
isValidEmail(e) {
/*
* This regex SHOULD capture 99% of valid e-mails, but it is from StackOverflow
* so I can't garuntee that. It works well in tests, but if it fails, lets switch
* to a simple /@/ or use the MailGun API.
*/
const emailRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/
const emailFieldValue = e.target.value
if (emailFieldValue.length == 0) {
this.setState({ validEmail: null })
require "nokogiri"
require "concurrent"
################################
# Methods
################################
def parse_data_into_chuncks(data)
chunks = {}
ccda.css("chunk section").each do |chunk|