Skip to content

Instantly share code, notes, and snippets.

View obahareth's full-sized avatar
🧉
In the Zone

Omar Bahareth obahareth

🧉
In the Zone
View GitHub Profile
@obahareth
obahareth / #ChatGPT Streaming.md
Created May 13, 2023 22:43 — 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.

@obahareth
obahareth / Gemfile
Created August 28, 2022 09:06 — forked from czj/Gemfile
Outputting Rails app logs to Logz.io via logstash
gem "lograge"
gem "logstash-event"
gem "logstash-logger"
@obahareth
obahareth / main.yaml
Created August 24, 2022 13:00 — forked from ArturT/main.yaml
GitHub Actions - how to run parallel tests in RSpec for Ruby on Rails project. See article how to run RSpec on GitHub Actions for Ruby on Rails app using parallel jobs https://docs.knapsackpro.com/2019/how-to-run-rspec-on-github-actions-for-ruby-on-rails-app-using-parallel-jobs or sign up at https://knapsackpro.com/?utm_source=github&utm_medium=…
# .github/workflows/main.yaml
name: Main
on: [push]
jobs:
test:
runs-on: ubuntu-latest
# If you need DB like PostgreSQL, Redis then define service below.
@obahareth
obahareth / squid_proxy_tutorial.md
Created August 15, 2022 10:37 — forked from jackblk/squid_proxy_tutorial.md
Tutorial on how to setup a squid proxy with authentication.

Note

This tutorial is for Ubuntu & Squid3. Use AWS, Google cloud, Digital Ocean or any services with Ubuntu to follow this tutorial.

Install squid & update

sudo apt-get update
sudo apt-get install squid3
sudo apt-get install apache2-utils
@obahareth
obahareth / README-container-as-systemd-service.md
Created August 15, 2022 06:31 — forked from drmalex07/README-container-as-systemd-service.md
Wrap a docker container in a systemd service. #docker #systemd.service #systemd #cgroups

README

Suppose we want to wrap a container running a Redis instance as a service.

Override unit file for docker daemon

We must override the service unit file that ships with docker (under /lib/systemd/system) in order to pass some cgroup-related options to the docker daemon. So, following the usual method to override parts of a unit file, we create the file /etc/systemd/system/docker.service.d/10-service.conf with contents:

@obahareth
obahareth / faraday_ssl_example.rb
Created July 19, 2022 09:24
An example on how to configure Faraday for SSL using client certificates, a private key, and a certificate authority file. This can help if you're getting errors like: TypeError (wrong argument type String (expected OpenSSL/X509))
# Taken from https://gist.github.com/mdeiters/975231?permalink_comment_id=3015720#gistcomment-3015720
def self.ping
connection = Faraday::Connection.new 'https://host:443/ping', ssl: {
ca_file: 'config/credentials/ROOT_CA.cer',
client_key: OpenSSL::PKey::RSA.new(File.read('config/credentials/client.key')),
client_cert: OpenSSL::X509::Certificate.new(File.read('config/credentials/agent.cer'))
}
connection.get.body
end
@obahareth
obahareth / extract_enum_mappings.md
Last active November 30, 2021 11:59
Extract Ruby on Rails enum values into a dictionary (represented by markdown tables).

README

Sometimes you have members from your data team who are looking at the database and have no idea what the enum integer values mean. This snippet of code helps to extract the readable names for those integers into markdown tables to help out your data team.

There are alternative approaches by using string enums via gems, or database enums, but this was made for an environment where those weren't an option (legacy enums, and no database enums available).

You could also put this into a Rake task and publish it into a wiki.

Usage

module RedisHashStore
extend self
class Entry
attr_reader :value
def initialize(value, expires_in:)
@value = value
@created_at = Time.now.to_f
@expires_in = expires_in
@obahareth
obahareth / Gemfile
Created July 5, 2020 10:58 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@obahareth
obahareth / install_notion_rtl.go
Created January 7, 2020 19:39
A Go script to install Notion RTL (on macOS only for now) for the desktop app. Sadly Notion recreates the HTML file this script modifies on whenever the app is relaunched, so the changes need to keep being reapplied.
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"runtime"