Skip to content

Instantly share code, notes, and snippets.

View joelmoss's full-sized avatar

Joel Moss joelmoss

View GitHub Profile
@joelmoss
joelmoss / bug.rb
Created June 22, 2023 10:25
Ruby inline standalone script
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 7.0.5'
@joelmoss
joelmoss / fix_active_record_jsonb.rb
Created June 5, 2023 08:15
Make Rails properly decode hashes and arrays in JSONB fields
# See https://til.magmalabs.io/posts/eb568eed39-make-rails-properly-decode-hashes-and-arrays-in-jsonb-fields-the-way-god-intended
ActiveRecord::Type::Json.class_eval do
# this is a json field, thus always decode it
def deserialize(value)
ActiveSupport::JSON.decode(value) rescue nil
end
def serialize(value)
if value.is_a?(::Array) || value.is_a?(::Hash)
const myFunc = function () {};
export default myFunc
@joelmoss
joelmoss / post-checkout.rb
Last active October 20, 2023 09:49
Maintain branch specific databases and switch on checkout
# frozen_string_literal: true
# rubocop:disable Metrics/LineLength
require 'yaml'
require 'digest'
require 'erb'
return if ENV['NO_DB_SWITCH'] == '1'
@joelmoss
joelmoss / post-checkout.rb
Created September 9, 2021 07:11
post-checkout git hook to switch Rails DB along with the branch
#!/usr/bin/env ruby
require 'yaml'
# Return if this is not a branch checkout.
return if ARGV[2] != '1'
def drop_existing_connections_to_database(database_name)
system(%[psql --command="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '#{database_name}' AND pid <> pg_backend_pid();" postgres > /dev/null])
end
@joelmoss
joelmoss / assets_anywhere.rb
Last active April 15, 2021 23:12
Include JS/CSS assets from anywhere in your Rails application - even outside /app/assets
module AssetsAnywhere
class Middleware
def initialize(app)
@app = app
@builder = Builder.new
end
def call(env)
@builder.attempt(env) || @app.call(env)
end
@joelmoss
joelmoss / side_load_assets.rb
Last active April 15, 2021 23:14
Side load JS/CSS assets alongside your Rails layout and view
module SideLoadAssets
module_function def append(view, path)
identifier = "/#{path}|"
path = Rails.root.join(path)
path.sub_ext('.js').exist? && view.content_for(:side_loaded_js, identifier)
path.sub_ext('.css').exist? && view.content_for(:side_loaded_css, identifier)
end
module Monkey
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" style="height: 100% !important; width: 100% !important; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; margin: 0 auto; padding: 0;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8"> <!-- utf-8 works for most cases -->
<meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->
<meta name="x-apple-disable-message-reformatting"> <!-- Disable auto-scale in iOS 10 Mail entirely -->
<title>You have a new session with %{client_name}</title> <!-- The title tag shows in email notifications, like Android 4.4. -->
import React from 'react'
import Modal from 'react-modal/lib/index'
Modal.setAppElement(document.getElementById('codio'))
Modal.injectCSS()
export default React.createClass({
displayName: 'ModalConfirm',
propTypes: {
HTTP ERROR 500
Problem accessing /ac2.server.core/. Reason:
Error creating bean with name 'jsonDispatcher' defined in URL [file:ac.resources/configs/server-beans.xml]: Cannot resolve reference to bean 'invoker' while setting bean property 'invoker'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoker' defined in URL [file:ac.resources/configs/server-beans.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonDispatcher' defined in URL [file:ac.resources/configs/server-beans.xml]: Cannot resolve reference to bean 'invoker' while setting bean property 'invoker'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoker' defined in URL [file:ac.resources/configs/server-beans.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: