Skip to content

Instantly share code, notes, and snippets.

Chris Edwards chrise86

Block or report user

Report or block chrise86

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrise86
chrise86 / call_template.rb
Last active Mar 2, 2018 — forked from juggy/call_template.rb
Render a complete page in rails 5 without controller
View call_template.rb
# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
@chrise86
chrise86 / rails_api_token_auth_with_tiddle.md
Created Jan 18, 2018 — forked from brunofacca/rails_api_token_auth_with_tiddle.md
Rails API token authentication with Tiddle gem in apps with web views
View rails_api_token_auth_with_tiddle.md

This gist attempts to explain how to implement token authentication in Rails, using Devise and Tiddle. Tiddle was designed to provide token auth for API-only Rails apps. However, the following instructions will enable you to use it in Rails apps which have both APIs and web views.

##Why Tiddle?

Devise is the obvious choice for authentication on Rails. However, token authentication was

@chrise86
chrise86 / application_helper.rb
Last active Nov 18, 2017 — forked from dnagir/application_helper.rb
Render a different variant in rails
View application_helper.rb
module ApplicationHelper
def with_variant(new_variant, &block)
old_variants = lookup_context.variants
begin
lookup_context.variants = [new_variant]
return block.call
ensure
lookup_context.variants = old_variants
end
end
@chrise86
chrise86 / pundit_namespaces.rb
Created Jul 25, 2017 — forked from spieker/pundit_namespaces.rb
Namespaces for Pundit policies
View pundit_namespaces.rb
# This concern enables namespaces in Pundit. In order to use it, put this
# module into the `app/controllers/concerns` folder of your project and then
# include the module into the controller you want to namespace the policies in
# after the include of Pundit.
#
# To secify the namespace to use, overwrite the `pundit_namespace` method on
# your controller then.
#
# Example
# =======
@chrise86
chrise86 / after.rb
Created Jul 25, 2017 — forked from mperham/after.rb
Thread-friendly shared connection
View after.rb
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
@chrise86
chrise86 / ruby_boolean.rb
Created Jul 12, 2017
How to implement a Boolean-Class for Ruby.
View ruby_boolean.rb
#
# DO NOT EXPECT THIS WILL RUN AS SHOWN HERE!
# This is an extract from https://github.com/iboard/yarb
# The specs will work only in the full environment of the application.
#
# Anyhow, this example should show you how to define a Boolean-value
# for ruby.
#
# Because HTML-Forms will post checkbox-values as "0"/"1" rather than false/true
# this class will handle 0,"0",false as FalseValue, and 1,"1",true as TrueValue
@chrise86
chrise86 / carrierwave.rb
Created Sep 8, 2016 — forked from iqbalhasnan/carrierwave.rb
carrierwave mini_magick image processing - quality, strip, exif rotation, gaussian blur, interlace
View carrierwave.rb
#config/initializers/carrierwave.rb
module CarrierWave
module MiniMagick
# Rotates the image based on the EXIF Orientation
def exif_rotation
manipulate! do |img|
img.auto_orient
img = yield(img) if block_given?
img
end
@chrise86
chrise86 / DropZone.jsx
Created Aug 20, 2016 — forked from pizza-r0b/01_DropZone.jsx
HTML5 Drag and Drop React Component
View DropZone.jsx
import React, {PropTypes} from 'react';
import classNames from 'classnames';
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
receiveFiles: PropTypes.func.isRequired,
View keybase.md

Keybase proof

I hereby claim:

  • I am chrise86 on github.
  • I am chrisedwards (https://keybase.io/chrisedwards) on keybase.
  • I have a public key whose fingerprint is 5D2F 502D 07D4 F2E2 1CD1 10AA C8CB 36A0 219B 6E85

To claim this, I am signing this object:

View dropzone-cropper.js
// transform cropper dataURI output to a Blob which Dropzone accepts
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg' });
}
You can’t perform that action at this time.