Skip to content

Instantly share code, notes, and snippets.

@ChristianAlexander
ChristianAlexander / detect.livemd
Last active May 5, 2025 14:09
Face Detection in Elixir

Face Detection in Elixir

Mix.install(
  [
    {:evision, "~> 0.1"},
    {:kino, "~> 0.7"}
  ],
@RStankov
RStankov / application_component.rb
Created April 25, 2024 11:56
ViewComponent Tips
class ApplicationComponent < ViewComponent::Base
private
def fetch_with_fallback(hash, key, fallback)
hash.fetch(key) do
ErrorReporting.capture_exception(%(key not found: "#{key}"))
fallback
end
end
@jpenalbae
jpenalbae / peek.sh
Last active October 9, 2024 19:45
Record desktop area on linux using slop and ffmpeg
#!/bin/bash
# Video Quality
# The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default,
# and 51 is worst quality possible. A lower value generally leads to higher
# quality, and a subjectively sane range is 17–28
QUALITY=28
# check if slop command exists
if ! command -v slop &> /dev/null
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active April 30, 2025 20:29
ChatGPT streaming with ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind!

How to add ChatGPT streaming to your Ruby on Rails 7 app!

This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!

Want more content like this, for free? Check out my free book, RailsAI!

Alt Text

@dhh
dhh / pagination_controller.js
Last active May 11, 2025 15:07
HEY's Stimulus Pagination Controller
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>
class SynchronousJob < ApplicationJob
def self.perform_later
raise "This job is not designed to be run asynchronously. Please use #perform_now"
end
end

ServiceNow - Jelly scripting cheatsheet

UI Page consists of jelly, client script and processing script. UI Macro has the jelly script only (but client script can be injected in jelly script) Usages:

  • Open as a page using URI https://<instance_name>.service-now/<ui_page_name>.do
  • Open as a modal using client script (UI action, client script, etc) (see snippet 1)
// Snippet 1
var gm = new GlideModal('UI_dialog_name');
gm.setTitle('Show title');
@rob-murray
rob-murray / asdf_install_ruby_ssl.sh
Created April 14, 2020 20:14
ASDF - Install Ruby with SSL
RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/opt/openssl" asdf install ruby 2.6.5
@katowulf
katowulf / firebase.json
Last active March 1, 2024 21:32
Example of Firebase emulator unit tests and seed Firestore data
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"emulators": {
"firestore": {
"port": 8080
}
}
@apauly
apauly / action_text_initializer.rb
Last active September 4, 2020 17:15
ActionText: Use preloaded ActiveStorage attachments
Rails.application.config.after_initialize do
ActiveSupport.on_load(:action_text_content) do
class_eval do
attr_accessor :rich_text
def attachment_for_node(node, with_full_attributes: true)
attachment = ActionText::Attachment.from_node(node, rich_text&.find_preloaded_attachable(node))
with_full_attributes ? attachment.with_full_attributes : attachment
end