Skip to content

Instantly share code, notes, and snippets.

View westonganger's full-sized avatar

Weston Ganger westonganger

View GitHub Profile
@westonganger
westonganger / stripe_checkout_requirements.md
Last active November 24, 2021 22:33
Stripe Checkout Requirements (2021)
@westonganger
westonganger / get_html_snapshot_jquery.js
Last active September 29, 2021 17:06
Get HTML Snapshot of Current Page with Javascript
/* Note: The html string returned fron this method will not contain any actual remotely referenced JS/CSS just the HTML as in the source */
window.get_html_snapshot = function(hideItems, hideClasses){
hideItems = hideItems || false;
hideClasses = hideClasses || ".modal, .modal-backdrop";
var input_types_to_skip = ["button", "submit", "file", "image", "password"];
// First write all input[type=text] field value so they can be seen when HTML is loaded
$('input').each(function(){
@westonganger
westonganger / js_error_handler.js
Last active September 29, 2021 17:45
Javascript Error Handler
// Links
// https://stackoverflow.com/questions/951791/javascript-global-event-mechanism
// https://stackoverflow.com/a/49560222/3068360
// https://stackoverflow.com/questions/5328154/catch-all-javascript-errors-and-send-them-to-server
window.addEventListener('error', function(event) {
// Instead of window.onerror we use addEventListener with capture option set to true to get the most errors
// window.onerror = function(message, file, line, col, error){
// https://stackoverflow.com/q/54209739/3068360
@westonganger
westonganger / postgresql_fdw_with_activerecord_and_rails.md
Last active November 16, 2023 04:25
Postgresql FDW with ActiveRecord and Rails

Source Article (See for latest changes): https://westonganger.com/posts/using-postgresql-fdw-with-activerecord-and-rails

If you want to do some cross database joins or includes across postgresql databases regardless of local or remote databases you can use Postgres FDW. Its an awesome tool for the job when you want to avoid data replication.

Base Postgresql FDW Model:

class PostgresFdwBase < ApplicationRecord

  ### Article to familiarize with concepts in this models methods - https://thoughtbot.com/blog/postgres-foreign-data-wrapper
@westonganger
westonganger / 1 static_rails.rb
Last active March 30, 2023 05:03 — forked from WattsInABox/.gitignore
Generate Static HTML Website Using Ruby on Rails
# config/environments/static.rb
require File.expand_path('../development', __FILE__)
# environment for serving static pages like error pages to upload to S3
MyApp::Application.configure do
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@pxdl
pxdl / nps2pkgi.py
Last active January 24, 2023 20:03
Converts the NoPayStation TSV for PS3 Games to pkgi-ps3 format
import csv
import urllib.request
url = "http://nopaystation.com/tsv/PS3_GAMES.tsv"
print('Downloading PS3_GAMES.tsv...')
urllib.request.urlretrieve(url, 'PS3_GAMES.tsv')
newlist = []
with open('PS3_GAMES.tsv', newline='', encoding="utf8") as csvfile:
listreader = csv.reader(csvfile, delimiter=' ', quotechar='"')
@qrush
qrush / application_job.rb
Last active March 31, 2020 01:38
Use Honeycomb to trace ActiveRecord calls inside of ActiveJob
class ApplicationJob < ActiveJob::Base
around_perform do |job, block|
Honeycomb.start_span(name: job.class.name) do |span|
span.add_field 'type', 'worker'
span.add_field 'queue.name', job.queue_name
block.call
end
end
end
@jeromedalbert
jeromedalbert / .gitattributes
Last active March 3, 2024 12:18
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (now works with Rails 5 and recent versions of Git). The following files should be in your home ~ directory. Inspired by https://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html
db/schema.rb merge=railsschema
@crittermike
crittermike / wget.sh
Last active March 26, 2024 22:49
Download an entire website with wget, along with assets.
# One liner
wget --recursive --page-requisites --adjust-extension --span-hosts --convert-links --restrict-file-names=windows --domains yoursite.com --no-parent yoursite.com
# Explained
wget \
--recursive \ # Download the whole site.
--page-requisites \ # Get all assets/elements (CSS/JS/images).
--adjust-extension \ # Save files with .html on the end.
--span-hosts \ # Include necessary assets from offsite as well.
--convert-links \ # Update links to still work in the static version.