Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="ISO-8859-1"?>
<?qbxml version="7.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<BillAddRq>
<BillAdd>
<VendorRef>
<ListID>80000438-1429823956</ListID>
</VendorRef>
<ItemLineAdd>
@r38y
r38y / console_fallback.js
Last active August 15, 2016 08:36
Make console.log bulletproof.
// see if the browser supports console.log - fail gracefully if it doesn't
try {
console.log();
console.debug();
console.assert();
} catch(e) {
console = {
log: function() {},
debug: function() {},
assert: function() {}
➜ disko git:(fix-rubypants) ✗ rbenv local 2.1.0
➜ disko git:(fix-rubypants) ✗ rspec
.......................................................................................................................................................................................
Finished in 9.92 seconds
183 examples, 0 failures
Randomized with seed 4522
# Add the following to your Gemfile
# gem 'rubypants-unicode', '~>0.2.3', require: false
begin
require 'rubypants-unicode'
rescue LoadError => _
abort "Missing dependency 'rubypants-unicode' for RubyPantsFilter."
end
module HTML
@r38y
r38y / four_oh_four.rb
Last active December 21, 2015 18:09
Render custom template for 404s
module FourOhFour
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::RecordNotFound, ActionController::RoutingError, with: :render_404
end
def render_404
render template: 'error_pages/404', status: :not_found, format: [:html] and return false
end
$(document).on 'click', '[data-confirm]', (event) ->
$target = $(event.target)
unless confirm($target.data('confirm'))
event.preventDefault()
return false
@r38y
r38y / rangy.rb
Created August 22, 2013 20:13
Controller concern for dealing with some range errors from misbehaving visitors.
module Rangy
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::StatementInvalid, RangeError, ArgumentError do |exception|
if exception.message =~ /is out of range for type integer|invalid offset|invalid value for Integer/
render text: 'Not found', status: :not_found
end
end
end
$(document).ready(function() {
var token = $('meta[name="csrf-token"]').attr('content')
$.ajaxPrefilter(function(options, originalOptions, xhr){
xhr.setRequestHeader('X-CSRF-Token', token);
})
})
@r38y
r38y / address.rb
Created August 5, 2013 14:32
Example refactoring of the class in Griddler that parses an email address.
module Griddler
class Address
def initialize(address)
@address = address
end
def some_method_name(type=:hash)
if type == :hash
parsed_address
else