| require "openai" | |
| client = OpenAI::Client.new( | |
| api_key: ENV.fetch("OPENROUTER_API_KEY"), | |
| base_url: "https://openrouter.ai/api/v1" | |
| ) | |
| models = %w{ | |
| google/gemma-2b-it | |
| anthropic/claude-sonnet-4 |
- You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use
rails newfirst to generate all of the boilerplate files necessary. - Create an app in the current directory with
rails new . - Use Tailwind CSS for styling. Use
--css tailwindas an option on therails newcall to do this automatically. - Use Ruby 3.2+ and Rails 8.0+ practices.
- Use the default Minitest approach for testing, do not use RSpec.
- Default to using SQLite in development.
rails newwill do this automatically but take care if you write any custom SQL that it is SQLite compatible. - An app can be built with a devcontainer such as
rails new myapp --devcontainerbut only do this if requested directly. - Rails apps have a lot of directories to consider, such as app, config, db, etc.
- Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
- Guard against incapable browsers accessing controllers with `allo
| #!/usr/bin/env ruby | |
| # deep_research.rb | |
| require 'openai' | |
| require 'json' | |
| require 'net/http' | |
| require 'uri' | |
| require 'timeout' | |
| require 'time' |
hi, i'm daniel. i'm a 15-year-old with some programming experience and i do a little bug hunting in my free time. here's the insane story of how I found a single bug that affected over half of all Fortune 500 companies:
If you've spent some time online, you’ve probably come across Zendesk.
Zendesk is a customer service tool used by some of the world’s top companies. It’s easy to set up: you link it to your company’s support email (like support@company.com), and Zendesk starts managing incoming emails and creating tickets. You can handle these tickets yourself or have a support team do it for you. Zendesk is a billion-dollar company, trusted by big names like Cloudflare.
Personally, I’ve always found it surprising that these massive companies, worth billions, rely on third-party tools like Zendesk instead of building their own in-house ticketing systems.
| # Additional reference here: | |
| # https://strftime.org | |
| require 'active_support/core_ext/integer/inflections' # To use .ordinalize() outside of rails | |
| date = Time.now | |
| date.strftime('%a %d %b %Y') | |
| # => Sun 08 Sep 2024 |
| # freeze_string_literal: true | |
| module CreateWithCallbacks | |
| extend ActiveSupport::Concern | |
| # Mimic the FactoryBot `create` method but with callbacks. All traits and overrides are applied. | |
| # | |
| # @example with traits and attributes | |
| # source_course = create_with_callbacks!( | |
| # :course, |
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!
- Follow me on Twitter for more Ruby AI at https://twitter.com/alexrudall
- Released under the MIT License - use as you wish :)
Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.
PostgreSQL Date/Time Documentation
The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.
The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.
| # Basic key operators to query the JSON objects : | |
| # #> : Get the JSON object at that path (if you need to do something fancy) | |
| # -> : Get the JSON object at that path (if you don't) | |
| # ->> : Get the JSON object at that path as text | |
| # {obj, n} : Get the nth item in that object | |
| # https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE | |
| # Date | |
| # date before today |
