Skip to content

Instantly share code, notes, and snippets.

@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
# Maven command to test a single class, also specifying a proxy server for remote communications
mvn -Dhttp.proxyHost=proxy_server -Dhttp.proxyPort=8900 test -Dtest=ServiceTest
# Maven command to print test report
mvn surefire-report:report-only
# maven goals to create a war without running tests
mvn -o clean compile war:war -Dmaven.test.skip=true
# gem install using proxy
jruby -S gem install builder -p http://proxy-server:8080