Skip to content

Instantly share code, notes, and snippets.

Avatar

Frank Kany kany

  • Rickman, TN
View GitHub Profile
@kany
kany / pagination_controller.js
Created Jun 4, 2021 — forked from dhh/pagination_controller.js
HEY's Stimulus Pagination Controller
View pagination_controller.js
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>
@kany
kany / Stripe-Webhooks-Rails-6.md
Created Apr 22, 2021
Testing Stripe Webhooks + Rails 6 on your local machine
View Stripe-Webhooks-Rails-6.md

Testing Stripe Webhooks + Rails 6 on your local machine

The document describes how to test Stripe Webhooks with Ruby On Rails on your local machine. Information in this document is current as of 4/22/2021.

  • Rails 6.1.3.1
  • Ruby 2.7.3p183
  • Stripe 1.5.14
@kany
kany / rails-6-send-mail-from-the-console.md
Last active Apr 8, 2021
Rails 6 - Sending mail from the console (As of April 2021)
View rails-6-send-mail-from-the-console.md

1) Create a new gmail account for testing

2) Enable Less secure app access - https://www.google.com/settings/security/lesssecureapps

3) Update config/environments/development.rb

  config.action_mailer.default_url_options = {host: "localhost", port: 3000}
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
@kany
kany / Terminal-Commands.md
Created Mar 29, 2021
Handy OSX Terminal Commands
View Terminal-Commands.md
@kany
kany / delete-old-git-branches.md
Created Feb 11, 2021
Delete old git branches
View delete-old-git-branches.md
View Mounting VirtualBox shared folders on Ubuntu Server 18.04 LTS (Bionic Beaver).md

Mounting VirtualBox shared folders on Ubuntu Server 18.04 LTS (Bionic Beaver)

This guide will walk you through the steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest.

Prerequisites

This guide assumes that you are using the following setup:

You could still make this guide work with other setups (possibly with some modifications to the commands and whatnot).

@kany
kany / rails6-actioncable-stimulus.md
Last active Oct 27, 2021
Rails 6 + ActionCable + Stimulus example for pushing updates to the view.
View rails6-actioncable-stimulus.md

Rails 6 + ActionCable + Stimulus example for pushing updates to the view.

This example will show how to push updates to the view for a Model instance that has changed without the user having to refresh the page.

This example focuses more on getting ActionCable working with Stimulus. If you don't already have stimulus setup in your app, here's a great write up on how to set it up: https://medium.com/better-programming/how-to-add-stimulus-js-to-a-rails-6-application-4201837785f9

Example scenario

  • You have a Scan model with attributes.
  • You have a ScanController#show action.
  • A user is viewing a Scan through the show.html.slim|haml|erb view template.
View stream-comments-with-rails-5-and-action-cable.md

Rails 5 and ActionCable

Assumptions: The application already exists. You have two models article.rb and comment.rb. Articles have two attributes, title and text. Comments have two attributes, text and article_id. See these instructions if you need help getting started.

Routes

Assuming that you are nesting your :comments resources inside of :articles, mount ActionCable and make sure you have a root.

config/routes.rb

Rails.application.routes.draw do
@kany
kany / README.md
Last active Sep 20, 2019
Toggle Wireless Mode
View README.md

Toggle Wireless Mode

This script will allow switching between managed and monitor mode for a wireless adapter.

Managed mode is the default wireless adapter mode.

Monitor mode allows monitoring all traffic received on a wireless channel and allows packets to be captured without having to associate with an access point.

Environment

@kany
kany / formatting_xml_or_json.rb
Created Feb 12, 2019
Formatting XML or JSON
View formatting_xml_or_json.rb
# resource - http://richardlog.com/post/12743073497/pretty-printing-json-and-xml-on-mac-osx
# Formatting XML
cat unformatted.xml | xmllint --format - > formatted.xml
# Formatting JSON
cat unformatted.json | python -m json.tool > formatted.json