Skip to content

Instantly share code, notes, and snippets.

@cmoran92
cmoran92 / preload_counts.rb
Last active October 19, 2020 11:24 — forked from apauly/preload_counts.rb
Preload the count of associations similar to the familiar "preload"
#
# PreloadCounts
#
# Usage:
# collection = Post.limit(10).preload_counts(:users)
# collection.first.users.count # fires one query to fetch all counts
# collection[1].users.count # uses the cached value
# collection.last.users.count # uses the cached value
#
# Call `::PreloadCounts.enable!` inside of an initializer to enable preloading of association counts
@cmoran92
cmoran92 / scroll-3.html
Last active November 12, 2018 15:38
Scrollable DIV with dynamic header and footer
<html>
<head>
<style>
body, .container {
height: 100%;
position: relative;
}
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td {
margin: 0;