Skip to content

Instantly share code, notes, and snippets.

@navjeetc
navjeetc / CONVENTIONS.md
Created February 22, 2025 20:45 — forked from peterc/CONVENTIONS.md
CONVENTIONS.md file for AI Rails 8 development
  • 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 new first 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 tailwind as an option on the rails new call 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 new will 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 --devcontainer but 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
@navjeetc
navjeetc / code-editor-rules.md
Created December 17, 2024 03:51 — forked from yifanzz/code-editor-rules.md
EP12 - The One File to Rule Them All

[Project Name]

Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.

Project Context

[Brief description ]

  • [more description]
  • [more description]
  • [more description]
@navjeetc
navjeetc / run_assistant.rb
Last active December 16, 2023 12:00
OpenAI assistants API usage
require 'openai'
client = OpenAI::Client.new(access_token: ENV['openai_key'])
assistants = OpenAI::Assistants.new(client: client)
# assistant = assistants.create(
# parameters: {
# name: 'Math tutor',
# model: 'gpt-4',
# instructions: 'You are a personal math tutor. Write and run code to answer math questions.'
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@navjeetc
navjeetc / update_contacts.js
Last active February 8, 2021 17:21
Update contacts csv file by adding headers/columns and updating values
function modifyForWeichertImport() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var deleteSecondaryAddressColumn = true
var secondaryAddressColumnNumber = 4
if (deleteSecondaryAddressColumn) {
// delete secondary address column
sheet.deleteColumn(secondaryAddressColumnNumber);
@navjeetc
navjeetc / Code.gs
Created August 15, 2020 18:24 — forked from dottedsquirrel/Code.gs
Code.gs - Spreedsheet to Magic API
/**
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
function getEnvironment() {
var environment = {
spreadsheetID: "<REPLACE WITH YOUR SPREADSHEET ID>",
firebaseUrl: "<REPLACE WITH YOUR REALTIME DB URL>"
};
@navjeetc
navjeetc / convert_time.rb
Last active June 14, 2020 04:19
Convert time from one time zone to another
# Converts time selectec time zone to time in Sydney Australia nad New Delhi in Rails
time_zones = ActiveSupport::TimeZone.all.map(&:name)
time_from = '2020-06-20 23:00:00'
Time.zone = time_zones.first #'America/New_York'
time_zones_to_convert_to = ["Australia/Sydney", "New Delhi"]
from_time = Time.zone.parse(time_from)
puts "From #{Time.zone} #{from_time}"
time_zones_to_convert_to.each do|to_zone|
puts "#{to_zone} #{from_time.in_time_zone(to_zone)}"
# disallow dotbot crawler
User-agent: dotbot
Disallow: /
@navjeetc
navjeetc / time_in_pak
Last active August 29, 2015 14:12
Time in Pak
tz = ActiveSupport::TimeZone.new("Islamabad")
# Time to be converted to Pak time
started_at = Time.now + 5.hours
started_at.in_time_zone(tz)
# grep some lines and remove some text from each grepped line and save the output to a file
grep getConn PCCASHPOS*.out | grep -v "JDBC.getConn" | sed 's/^.*getConnection\|//' > /tmp/conn.out