Skip to content

Instantly share code, notes, and snippets.

View ffullenk's full-sized avatar

Francisco Fullenkamp ffullenk

View GitHub Profile
@elico
elico / sign-pdf.rb
Created October 2, 2017 08:41
Siginging pdf with origami and OpenSSL on ruby 2.x+
#!/usr/bin/env ruby
require 'openssl'
require 'time'
begin
require 'origami'
rescue LoadError
abort 'origami not installed: gem install origami'
end

Realtime Notifications with ActionCable

In this episode we're going to be adding realtime notifications into your app using ActionCable. We've talked about notifications a few times in the past and we used AJAX polling for that. 95% of the time, polling is the solution that would be recommended for it.

But if you're looking for a good introduction into ActionCable then this is a decent one because we're only really using it for one way from the server side to the client side.

Getting started

So to get started we're starting with an app that has Bootstrap installed and then we created a Main controller with an index view which is where we will list our Notifications as for this example.

Before we generate our channels let's install a few things

@namnv609
namnv609 / ws-with-apache2-proxy.conf
Last active February 12, 2019 21:13
ActionCable WebSocket with Apache2 proxy
<VirtualHost *:80 *:443>
# Domain
ServerName servername.domain
SSLEngine On
SSLProxyEngine On
# Path to SSL CRT file
SSLCertificateFile /etc/apache2/ssl/apache.crt
# Path to SSL KEY file
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
@pescobar
pescobar / build-git.sh
Created October 5, 2015 07:14
compile git with openssl instead of gnutls
#!/usr/bin/env bash
# Clear out all previous attempts
rm -rf "/tmp/source-git/"
# Get the dependencies for git, then get openssl
sudo apt-get install build-essential fakeroot dpkg-dev -y
sudo apt-get build-dep git -y
sudo apt-get install libcurl4-openssl-dev -y
mkdir -p "/tmp/source-git/"
@salmanasiddiqui
salmanasiddiqui / notifications_controller.rb
Last active March 20, 2024 18:58
Right way to use Rails SSE for live notification
class NotificationsController < ApplicationController
def notify_me
# Rails reserve a db connection from connection pool for each request, lets put it back into connection pool.
ActiveRecord::Base.clear_active_connections!
# required header
response.headers['Content-Type'] = 'text/event-stream'
sse = ActionController::Live::SSE.new(response.stream)
@rocksfrow
rocksfrow / clone_schema_fn.sql
Last active July 13, 2022 10:19
enhanced postgresql clone_schema() function with trigger + foreign key support
CREATE OR REPLACE FUNCTION clone_schema(source_schema text, dest_schema text) RETURNS void AS
$$
DECLARE
object text;
buffer text;
default_ text;
column_ text;
constraint_name_ text;
constraint_def_ text;
@blairanderson
blairanderson / simple_form_select_with_data.md
Last active December 4, 2018 15:07
Rails Bootstrap Simple_Form Select with Data Attributes

This was super annoying so i decided to write it down.

I needed to add some data attributes to a simple_form input(f.input :people, as: :select) and also maintain the bootstrap classes

Here's how i solved it:

<%= f.input :car_id, label: 'Select a Car' do %>
    <%= f.select :car_id, @cars.map { |car| [car.name, car.id, {'data-car-price' => car.current_price}] }, {include_blank: true}, {class: 'form-control'} %>
&lt;% end %&gt;
@temochka
temochka / postmark_rails_headers.rb
Created April 29, 2014 14:39
An example of sending custom headers with postmark-rails and ActionMailer
class TestMailer < ActionMailer::Base
def email
headers['X-Tag-Via-Hash-Access'] = 'value'
headers 'X-Tag-Via-Headers-Method' => 'value'
mail(to: '[email protected]', from: '[email protected]', subject: 'Headers test') do |format|
format.text { render text: 'Headers test' }
end
@ryantownsend
ryantownsend / carrierwave_direct.rb
Created April 17, 2014 04:22
Patches CarrierWave Direct to fix signature not matching errors, as per https://github.com/dwilkie/carrierwave_direct/pull/128
# config/initializers/carrierwave_direct.rb
require "carrierwave_direct"
module CarrierWaveDirect
module SignatureFixMonkeyPatch
def policy(options = {})
options[:expiration] ||= upload_expiration
options[:min_file_size] ||= min_file_size
options[:max_file_size] ||= max_file_size
@lfender6445
lfender6445 / gist:9919357
Last active May 13, 2025 16:00
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger