Skip to content

Instantly share code, notes, and snippets.

View ValterAndrei's full-sized avatar
🏠
Working from home

Valter Andrei ValterAndrei

🏠
Working from home
  • Poços de Caldas - MG, Brasil
View GitHub Profile
# frozen_string_literal: true
module Aws
# Client for AWS Cognito Identity Provider using Secure Remote Password (SRP).
#
# This code is a direct translation of the Python version found here:
# https://github.com/capless/warrant/blob/ff2e4793d8479e770f2461ef7cbc0c15ee784395/warrant/aws_srp.py
class CognitoSrp
def initialize(username:, password:, pool_id:, client_id:, aws_client:)
@username = username
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active April 19, 2024 04:06
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@erdostom
erdostom / Dockerfile
Last active November 25, 2022 14:53
Good starter Dockerfile + docker-compose.yml for Rails 6.
FROM ruby:2.6.5-alpine
RUN apk add --update --no-cache bash build-base nodejs sqlite-dev tzdata postgresql-dev yarn
RUN gem install bundler:2.1.4
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn install --check-files
@lucaspiller
lucaspiller / .gitlab-ci.yml
Last active April 14, 2022 09:07
Rails 5.2 + Docker + Gitlab Continuous Deployment
image: ruby:2.6
services:
- postgres:11-alpine
variables:
POSTGRES_DB: myorg_test
CONTAINER_IMAGE: registry.gitlab.com/myorg/myapp
stages:
@saboyutaka
saboyutaka / Dockerfile
Created July 28, 2018 06:20
Docker Compose for Rails
FROM ruby:2.5.1
ENV LANG C.UTF-8
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
libfontconfig1 \
less \
@falvarez
falvarez / docker-shell.sh
Created January 24, 2018 08:10
Run docker container, mount current working directory and get interactive shell
docker run -ti -v $(pwd):/tmp DOCKER_IMAGE /bin/bash
@rahsheen
rahsheen / rspec_mock_net_http.rb
Created November 30, 2017 19:33
Easily Mock Net::HTTP with Rspec
require 'rails_helper'
RSpec.describe MyWorker, type: :job do
include ActiveJob::TestHelper
let(:sqs_msg) { double AWS::SQS::ReceivedMessage,
id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e',
body: 'test',
delete: nil }
@primaryobjects
primaryobjects / react-confirm.js
Created November 1, 2017 19:03
A simple example of a confirm alert dialog in ReactJs / React.
<div className='delete-button' onClick={() => { if (window.confirm('Are you sure you wish to delete this item?')) this.onCancel(item) } } />
@wbotelhos
wbotelhos / clear-sidekiq-jobs.sh
Last active April 2, 2024 10:04
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear

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