Skip to content

Instantly share code, notes, and snippets.

class Book::GenreAutomation
attr_accessor :book
def initialize(book_id)
self.book = Book.find(book_id)
end
def run
genres_array = fetch_genres_from_openai
def run
genres_array = fetch_genres_from_openai
return if genres_array.blank?
book.genres.clear
genres_array.each do |genre_name|
genre = Genre.find_by(name: genre_name)
client = OpenAI::Client.new
response = client.chat(
parameters: {
model: 'gpt-4o', # Required.
response_format: { type: 'json_object' },
messages: [{ role: 'user', content: content }], # Required.
temperature: 0.7
}
)
class Book::GenreAutomation
attr_accessor :book
def initialize(book_id)
self.book = Book.find(book_id)
end
end
@sbatson5
sbatson5 / openai_initializer.rb
Created January 22, 2025 16:55
openai initializer
OpenAI.configure do |config|
config.access_token = 'YOUR_ACCESS_TOKEN'
config.organization_id = 'YOUR_ORGANIZATION_ID'
config.log_errors = Rails.env.development?
end
const getComments = () => {
return onSnapshot(collection(db, 'comments'), (value) => {
const comments = value.docs.reduce((acc, item) => {
if (id.id === item.data().coinId) {
acc.push({ ...item.data(), id: item.id })
}
return acc;
}, [])
setComments(comments);
});
const FONT_FACES = `@font-face {
font-display: auto;
font-family: "Elections-Publico";
font-style: normal;
font-weight: 800;
src: url("https://some-url.com/fonts/Publico-Bold.woff") format("woff");
}
@font-face {
font-display: auto;
font-family: "Elections-Akkurat-Mono";
@sbatson5
sbatson5 / component.js
Last active February 25, 2020 18:16
Step 6
class CandidateImage extends HTMLElement {
connectedCallback() {
this.shadow = this.attachShadow({ mode: 'open' });
this.setupImage();
this.addWinnerText();
// Add our styles
this.createStyles();
}
@sbatson5
sbatson5 / component.js
Last active February 25, 2020 18:16
Step 5
class CandidateImage extends HTMLElement {
connectedCallback() {
this.shadow = this.attachShadow({ mode: 'open' });
// Create an image
const image = new Image();
// Find the right image for the provided name
if (this.getAttribute('name') === 'pete') {
image.src = 'https://cdn-candidates.com/pete.jpg';
@sbatson5
sbatson5 / component.js
Last active February 25, 2020 15:17
Step 4
class CandidateImage extends HTMLElement {
connectedCallback() {
this.shadow = this.attachShadow({ mode: 'open' });
// Create an image
const image = new Image();
// Find the right image for the provided name
if (this.getAttribute('name') === 'pete') {
image.src = 'https://cdn-candidates.com/pete.jpg';