Skip to content

Instantly share code, notes, and snippets.

@rbarazi
rbarazi / #ChatGPT Streaming.md
Created April 29, 2024 00:26 — forked from alexrudall/#ChatGPT Streaming.md
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.

@rbarazi
rbarazi / kafka_setup_mac.md
Last active March 3, 2023 14:45 — forked from siliconsenthil/kafka_setup_mac.md
Install Kafka in Mac

Installation

Install kafka

brew install kafka

The above will install kafka and it's dependency zookeeper

You can start in the background by

@rbarazi
rbarazi / postgres_queries_and_commands.sql
Created June 12, 2020 14:44 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@rbarazi
rbarazi / nginx-passenger-ssl.conf
Created November 10, 2016 22:23 — forked from rkjha/nginx-passenger-ssl.conf
Nginx/Passenger config when using SSL with a Ruby/Rails Application.
# for redirecting hhtp traffic to https version of the site
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
# for redirecting to non-www version of the site
server {
listen 80;
@rbarazi
rbarazi / gist:337f470bf957cd16daf9b6b33bebef17
Created June 15, 2016 14:26 — forked from gkop/gist:1371962
Capture javascript errors in Cucumber+Capybara+Webdriver tests
# in features/support/env.rb
require 'selenium/webdriver'
# we need a firefox extension to start intercepting javascript errors before the page
# scripts load
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
# see https://github.com/mguillem/JSErrorCollector
profile.add_extension File.join(Rails.root, "features/support/extensions/JSErrorCollector.xpi")
Capybara::Selenium::Driver.new app, :profile => profile
@rbarazi
rbarazi / ssl_hack.rb
Created June 15, 2016 13:42 — forked from Papierkorb/ssl_hack.rb
SSL with Capybara and Selenium
# Hack for Capybara to use SSL connections using selenium.
#
### Usage:
# Require this from rails_helper.rb
#
### Steps to generate a SSL certificate on a Linux box:
# 0. Starting from 'Rails.root'
# 1. Generate private key. Type in some password.
# $ openssl genrsa -des3 -out private.key 4096
# 2. Generate certificate sign request
# patch for make ruby error
# % rbenv install 1.8.7-p375
# ...
# ossl_pkey_ec.c:815: error: ‘EC_GROUP_new_curve_GF2m’ undeclared (first use in this function)
# ossl_pkey_ec.c:815: error: (Each undeclared identifier is reported only once
# ossl_pkey_ec.c:815: error: for each function it appears in.)
# make[1]: *** [ossl_pkey_ec.o] error 1
# ...
#
# refs: http://forums.cpanel.net/f5/case-84173-error-installing-ruby-377831.html
@rbarazi
rbarazi / how-to-set-up-stress-free-ssl-on-os-x.md
Created January 5, 2016 17:10 — forked from jed/how-to-set-up-stress-free-ssl-on-os-x.md
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
(function() {
// Usage:
//
// <script src='http://pressly.com/redirect.js' type='text/javascript'></script>
// <script>Pressly.redirect("http://tablet.domain.com");</script>
//
/* >> Generated code from Issue Config */
// Supported devices to redirect