Skip to content

Instantly share code, notes, and snippets.

View jcuervo's full-sized avatar
💭
I may be slow to respond.

Chard Gonzales jcuervo

💭
I may be slow to respond.
View GitHub Profile
@jcuervo
jcuervo / postgresql_notify_trigger.md
Last active December 13, 2024 06:34
Using PostgreSQL Notify and Trigger Functions in Ruby on Rails

Using PostgreSQL Notify and Trigger Functions in Ruby on Rails

One of the advanced features of PostgreSQL is the NOTIFY and LISTEN functionality. These features enable real-time communication between databases and applications. Modern web applications that requires event-driven behavoir and real-time updates will benefit from this.

Combining these features with Ruby on Rails can create powerful real-time applications with minimum overhead.

NOTIFY and LISTEN

The NOTIFY and LISTEN features allows a database session to send and receive asynchoronous messages. With NOTIFY, a session broadcasts a message on a specific channel. LISTEN allows other sessions to subscribe to those messages. The mechanishm enables real-time communication and thus reducing the need for continous polling of the database.

@jcuervo
jcuervo / enums_for_scoping.md
Last active June 26, 2024 00:26
Unveiling the Power of Enums for Scoping Queries in Rails

Unveiling the Power of Enums for Scoping Queries in Rails

Provided in ActiveRecord, enums are used to define a set of named values for an attribute on a model. The basic implementation for enums are for attributes that relates to status, stages and states.

class Task < ApplicationRecord
  enum status: { pending: 0, active: 1, completed: 2, paused: 3, archived: 4 }
end
@jcuervo
jcuervo / twilio_messaging_service.rb
Created August 23, 2023 23:55
Send Message via net/http for Twilio Messaging Service
require 'uri'
require 'net/http'
class TwilioMessage
def initialize(options = {})
@account_sid = ENV.fetch('TWILIO_ACCOUNT_SID')
@account_token = ENV.fetch('TWILIO_AUTH_TOKEN')
@message_service_sid = ENV.fetch('TWILIO_MSID')
import { Injectable } from '@angular/core';
@Injectable()
export class AppSettingsProvider {
endPoint: string;
baseUrl: string;
mode: string;
constructor() {
@jcuervo
jcuervo / Autobackup PostGres to AWS
Last active May 21, 2016 05:51
Run an auto-backup script from Ubuntu (running Ruby on Rails app) on PostGres database.
Attempt to run an auto-backup script from DigitalOcean Ubuntu Droplet (running Ruby on Rails app) on PostGres database.
1. Setup s3cmd
S3cmd will upload the backup files generated.
The `sync` command will be executed after the autopostgresqlbackup script finished it's job (added on the POSTBACKUP command).
Follow the steps enumerated in https://levels.io/backup-linode-digital-ocean-vps-amazon-s3/ until the recusive part:
s3cmd sync --recursive --preserve /your-folder-name-to-backup s3://nameofyours3bucket
2. Setup AutoPostGresqlBackup
Follow the instructions in the `Installing and configuring autopostgresqlbackup in CentOS 7` from:
def attempt_login
authorized_user = User.authenticate(params[:username], params[:hashed_password])
unless authorized_user.eql?(false)
session[:user_id] = authorized_user.id
session[:username] = authorized_user.username
case authorized_user.account_type
when "admin"
redirect_to :action => "index"
when "it"
redirect_to :action => "it"