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
@excid3
excid3 / scaffold_generator.rb
Created February 7, 2024 15:56
Override rails:scaffold generator to add features like Turbo 8 refreshes
class ScaffoldGenerator < Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)
# Run rails:scaffold with the same arguments and options
hook_for :scaffold, in: :rails, default: true, type: :boolean
def turbo_refreshes
# Scaffold generator will have already removed this file on revoke
return if behavior == :revoke
@excid3
excid3 / dynamic-nginx-module-ubuntu-18.04.sh
Created June 20, 2018 17:58
How to compile a dynamic nginx module for Ubuntu 18.04
# Install dependencies that nginx was originally compiled with
sudo apt install libperl-dev libgeoip-dev libgd-dev
# Get the nginx source
wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
# Get the module source
wget https://github.com/fdintino/nginx-upload-module/archive/master.zip
unzip master.zip

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

class Request
attr_reader :exception, :response
def initialize(context = {})
@context = context
end
def execute
@response ||= Response.call(execute_request)
self
[color]
ui = true
[user]
name = Chris Oliver
email = excid3@gmail.com
signingkey = 0E881BAF04745832
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
# 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 / 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.

require 'open-uri'
require 'nokogiri'
page = open('http://www.ncbi.nlm.nih.gov/pubmed/?term=asdf')
doc = Nokogiri::HTML(page)
# Get all the links on the page inside the results
links = doc.css(".rprt .title a")
#=> [
#<Nokogiri::XML::Element:0x3fc61e11898c name="a" attributes=[#<Nokogiri::XML::Attr:0x3fc61e118900 name="href" value="/pubmed/26754126">,
@excid3
excid3 / 024-liking-posts.md
Created October 29, 2016 00:27
GoRails Transcript 024 - Liking Posts

Liking Posts

A common feature of applications these days is the ability to like or favorite a post on websites.

Today we're going to talk about implementing that and submitting it via an AJAX request.

We're starting with a simple application that has posts and users. Anyone is able to create a blog post and click on them and view. But we want to add the ability for a user to click a link and Like the post.

The first step we need to take is to create a model to represent the association between the user and the post they liked.