Skip to content

Instantly share code, notes, and snippets.

View excid3's full-sized avatar
:shipit:
Shipping

Chris Oliver excid3

:shipit:
Shipping
View GitHub Profile
# frozen_string_literal: true
# == AuthenticatesWithTwoFactor
#
# Controller concern to handle two-factor authentication
module AuthenticatesWithTwoFactor
extend ActiveSupport::Concern
def prompt_for_two_factor(user)
@user = user
@excid3
excid3 / _attachment.html.erb
Last active May 7, 2019 14:39 — forked from aymorgan/_attachment.html.erb
JQuery File Upload, Amazon S3 and Shrine - rendering with a partial
<!-- app/views/attachments/_attachment.html.erb -->
<div class="attachment-image col-xs-6 col-sm-4 col-md-3" id="attachment_<%= @report.slug %><%= attachment.id %>elv1">
<div class="row">
<div class="attached-image-wrapper col-xs-12">
<a class="attached-image" data-lightbox="report-attachment" style="background-image:url('<%= attachment.image_url(:preview) %>');" href="<%= attachment.image_url(:original) %>"></a>
</div>
</div>
<div class="attachment-options-wrapper">
@excid3
excid3 / middleware.rb
Created March 5, 2018 03:14 — forked from romaimperator/middleware.rb
Middleware to support prefixed value in the url
class MyMiddleware
def initialize(app)
@app = app
@message = message
end
def call(env)
dup._call(env)
end
@excid3
excid3 / letsencrypt_2016.md
Created February 28, 2017 23:56 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two modes when you don't want Certbot to edit your configuration:

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80) to renew certificates.

In the following, we're setting up mydomain.com to be served from /var/www/mydomain, and challenges will be served from /var/www/letsencrypt.

What's up guys? In this episode we're going to talk about devise masquerading and how to add this gem so that you can login as other users to make doing suppport and finding and reproducing books a little bit easier.

This is really useful in development but it can also be really useful in production if you have the need to do some support and maybe login into someone's account and try to do something and reproduce the bug or maybe just you know help them with their account so we're going to talk about the devise masquerade gem and then I'd like to do a follow-up where we talked about how this is actually implemented behind the scenes because it's actually rather interesting and not as complicated as you might think.

So this gem is a extension for devise so you're gonna have to have devise installed in order to use it. It basically just hooked in and you have a few message that you can use so you have devised master able and in your application controller you put in before filter mastery user and uh then y

class RepliesController < ApplicationController
require "time"
skip_before_filter :verify_authenticity_token
skip_before_filter :authenticate_teacher!
def receive
# 1. set a @parent based on phone number and/or course number if they exist
# 2/ you then move on to the next state on the parent
@reply = Reply.new
def close_call(medic, call)
@call = call
@medic = medic
recipients = [@medic.medic_sms, @medic.medic_email]
recipients << @call.transferred_from.facility_email if @call.transferred_from.facility_email?
mail to: recipients, subject: "Call Complete: #{@call.incident_number}"
end
def index
@calls = Call.report(params[:search])
respond_to do |format|
format.html do
@calls.paginate(:per_page => 10, :page => params[:page])
end
format.csv { send_data @calls.to_csv }
format.xls { send_data @calls.to_csv(col_sep: "\t") }
end
end
@excid3
excid3 / time_formatter.rb
Created September 6, 2012 16:41
Format time differences in seconds
class TimeFormatter
def self.format_time(elapsed)
return if elapsed.nil?
seconds = elapsed % 60
minutes = (elapsed / 60) % 60
hours = (elapsed / 3600)
"%d:%02d:%02d" % [hours, minutes,seconds]
# hours.to_s + ":" + format("%02d",minutes.to_s) + ":" + format("%02d",seconds.to_s)
@excid3
excid3 / chef_solo_bootstrap.sh
Created September 4, 2012 19:21 — forked from joelash/chef_solo_bootstrap.sh
Bootstrap Ruby 1.9.3 And Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local
make
make install