Skip to content

Instantly share code, notes, and snippets.

@jasonkarns
jasonkarns / mailer_preview_helper.rb
Last active May 27, 2021 15:23
A helper to generate mailer previews automatically (or more easily) for each action that exists on the mailer.
module MailerPreviewHelper
extend ActiveSupport::Concern
included do
# Allows a mailer preview to override `params` method (either class or instance level)
# to define the hash that will be passed to the mailer by default by the `preview` helper.
class_attribute :params, default: {}, instance_accessor: false
mailer.instance_methods(false).each do |action|
define_method(action) { mailer.with(**params).send action }
@al2o3cr
al2o3cr / README.md
Created June 25, 2018 10:44
STI method generation optimization

Reducing STI memory usage

if there are many STI child classes, ActiveRecord generates methods for each one individually. This is wasteful in the typical case, since all the children share the same underlying columns.

The small patch included here causes those methods to instead be generated in the parent class, shared amongst all the subclasses.

DO NOT use this if you call methods like attribute :foo to adjust the typecasting of columns in individual models.

@maxivak
maxivak / webpacker_rails.md
Last active April 13, 2023 18:46
Webpack, Yarn, Npm in Rails
@samjonester
samjonester / How.md
Last active May 23, 2022 11:36
Tmate + Tmux pairing!

Tmate + Tmux pairing

Tmate is used as the "free reverse ssh tunnel". It is not super secure because a key is not required to connect, but it sure is conventient. Tmux is used inside the Tmate session to share multiple terminal windows


Here's the situation.

You've createe a new tmux session where you will do your work named foo.

@PurpleBooth
PurpleBooth / README-Template.md
Last active May 28, 2024 08:25
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@bridgetkromhout
bridgetkromhout / AWS ELB pre-warming questions
Created January 23, 2014 16:25
AWS ELB pre-warming questions. These questions (and sample answers) were provided by AWS support on 2013-11-26; I've edited slightly for clarity.
0. What is the name of the ELB which needs to be pre-warmed?
a. e.g. yourwebapp-yourcompany-123456789.us-east-1.elb.amazonaws.com
1. What is the approximate increase percentage in traffic, or expected requests/sec that will go through the load balancer (whichever is easier to answer)?
a. e.g. 3,500 per second
2. Do you know the average amount of data passing through the ELB per request/response pair?
a. e.g. Roughly 250KB.
3. Expected percent of traffic going through the ELB that will be using SSL termination?
@halcyonCorsair
halcyonCorsair / Vagrantfile
Created September 5, 2012 21:10
A json file for chef-solo, and the equivalent Vagrantfile to setup koha
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@vitobotta
vitobotta / resque-recovery.sh
Created May 24, 2012 18:53
Resque: automatically kill stuck workers and retry failed jobs
#!/bin/bash
# Also see: http://vitobotta.com/resque-automatically-kill-stuck-workers-retry-failed-jobs/
[[ -f /tmp/retry-failed-resque-jobs ]] && rm /tmp/retry-failed-resque-jobs
ps -eo pid,command |
grep [r]esque |
grep "Processing" |
while read PID COMMAND; do
@theconektd
theconektd / github.css
Created April 30, 2012 02:11
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {