Skip to content

Instantly share code, notes, and snippets.

@ChristianAlexander
ChristianAlexander / detect.livemd
Last active May 24, 2024 05:50
Face Detection in Elixir

Face Detection in Elixir

Mix.install(
  [
    {:evision, "~> 0.1"},
    {:kino, "~> 0.7"}
  ],
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active May 27, 2024 15:20
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!

Alt Text

First, add the ruby-openai gem! Needs to be at least version 4. Add Sidekiq too.

@dhh
dhh / pagination_controller.js
Last active April 24, 2024 10:53
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
@lazaronixon
lazaronixon / dropzone_controller.js
Last active March 9, 2024 05:14
Dropzone.js + Stimulus + Active Storage
import { Controller } from "stimulus"
import { DirectUpload } from "@rails/activestorage"
import Dropzone from "dropzone"
import { getMetaValue, findElement, removeElement, insertAfter } from "helpers"
Dropzone.autoDiscover = false
export default class extends Controller {
static targets = [ "input" ]
@dianjuar
dianjuar / i3-shortcuts-screenshot.md
Last active May 31, 2024 14:38
My i3 shortcuts to take screenshots

Requirements

  • maim
  • xclip

Set-up

Set this on your i3 config file ~/.i3/config

# Screenshots