Skip to content

Instantly share code, notes, and snippets.

View jeremygottfried's full-sized avatar

Jeremy Gottfried jeremygottfried

View GitHub Profile
#models/post.rb
class Post < ApplicationRecord
belongs_to :user, touch: true
after_save :create_json_cache
def self.cache_key(posts)
{
serializer: 'posts',
#controllers/user_controller.rb
class UserController < ApplicationController
def index
users = User.includes(:posts)
json = Rails.cache.fetch(User.cache_key(users)) do
users.to_json(include: :posts)
end
render json: json
{
var private = "I am unreachable";
}
// => undefined
{
var private = "I am unreachable";
}
// => undefined
@jeremygottfried
jeremygottfried / serverReady.js
Created March 4, 2022 19:02
Check if a server is ready in node.js
import http from 'http';
function delay(time) {
return new Promise(((resolve) => {
setTimeout(resolve, time);
}));
}
function serverReady() {
return new Promise(((resolve) => {