This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def record_event!(action, user: Current.user, record: nil, extra: {}, throttle: false, throttle_amount: 5.minutes) | |
if throttle.present? | |
existing = events.find_by(action: action, record: record, user: user, occurred_at: throttle_amount.ago..) | |
return existing if existing&.touch(:occurred_at) | |
end | |
events.create!(action: action, record: record, user: user, extra: extra) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus"; | |
export default class extends Controller { | |
static targets = ["source"]; | |
copy() { | |
const range = document.createRange(); | |
window.getSelection().removeAllRanges(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Posts</h1> | |
<ul> | |
<% Post.all.each do |p| %> | |
<li><%= p.title %></li> | |
<% end %> | |
</ul> | |
<%= link_to "+ Post", new_posts_path, remote: true %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add color coding based on Rails environment for safety | |
if defined? Rails | |
banner = if Rails.env.production? | |
"\e[41;97;1m #{Rails.env} \e[0m " | |
else | |
"\e[42;97;1m #{Rails.env} \e[0m " | |
end | |
# Build a custom prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Formats a +number+ into an abbreviated string suitable for | |
# displaying social media type metrics | |
# | |
# ==== Options | |
# * start_at - The first number to start abbreviating, defaults | |
# to 10_000. Certain metrics may want to start at e.g. 1000. | |
# | |
# ==== Examples | |
# number_to_social(123) # => 123 | |
# number_to_social(1457) # => 1457 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:plain | |
var existingModal = document.querySelector("[data-controller='modal']"); | |
if (existingModal) { | |
document.body.removeChild(existingModal); | |
} | |
document.body.insertAdjacentHTML("beforeend", "#{j render partial: template.to_s, locals: local_assigns }"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div | |
class="inline-block" | |
data-controller="hovercard" | |
data-hovercard-url-value="<%= hovercard_user_path(e.user) %>" | |
data-action="mouseenter->hovercard#show mouseleave->hovercard#hide" | |
> | |
<%= link_to e.user.username, e.user, class: "font-bold hover:text-gray-700" %> | |
</div> | |
<span> | |
<%= e.action %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-controller="clipboard" class="mt-4 bg-gray-50 p-6"> | |
<input type="text" class="form-input bg-grey-50" value="SeCrEtKeY-42!" data-clipboard-target="source" readonly /> | |
<button class="btn" data-clipboard-target="button" data-action="clipboard#copy"> | |
Copy | |
</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-controller="counter" data-counter-count-value="7" class="flex flex-col mt-3"> | |
<div class="text-2xl"> | |
The count is: <span data-counter-target="result"></span> | |
</div> | |
<div class="flex space-x-4 mt-4"> | |
<button class="btn" data-action="counter#increment">+</button> | |
<button class="btn" data-action="counter#decrement">-</button> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus"; | |
export default class extends Controller { | |
static targets = ["count"]; | |
connect() { | |
this.setCount(); | |
} | |
checkAll() { |
NewerOlder