Skip to content

Instantly share code, notes, and snippets.

View erbmicha's full-sized avatar

Michael Erb erbmicha

View GitHub Profile
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active June 22, 2024 02:41
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!

Want more content like this, for free? Check out my free book, RailsAI!

Alt Text

@seanlilmateus
seanlilmateus / gist:7777282
Last active December 30, 2015 04:39
THREAD-SAFETY for every one... simple way to wrap any object with a thread-safe wrapper,
class << NSProxy
def method_added(meth)
end
def inherited(klass)
end
end
class Proxy < NSProxy
def self.const_missing(n)
@thbar
thbar / Guardfile
Last active December 15, 2015 10:28
How to automatically restart the simulator in RubyMotion when code is updated (beta version!)
require 'childprocess'
guard 'shell' do
watch %r{^app/(.+)\.rb$} do |m|
`killall rake`
# Why this:
# - spawn a child process to avoid locking Guard
# - make sure that the child process has stdout and stdin otherwise it crashes
# - bonus point: get REPL access in the simulator!
@tlowrimore
tlowrimore / union_scope.rb
Last active January 13, 2023 21:12
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
class MyViewController < UIViewController
include ViewTags
#by convention, these views will have tags that correspond to the order you specify them in
# :date_label:1, :name_label:2
has_view :date_label, :name_label
def loadView
views = NSBundle.mainBundle.loadNibNamed "myview", owner:self, options:nil
self.view = views[0]

This is a distillation of a technique we use internally at Basho to reduce the pain of cloning some of our larger repos. It relies a bit on shell scripts and environment variables, but it can be run more directly, as I show below.

  1. Create a bare git repository in some directory, e.g. /var/lib/gitcache.

    git init --bare /var/lib/gitcache
  2. Add all repositories you want to cache as remotes to the git repository, e.g.

@nrrrdcore
nrrrdcore / list.css
Created August 20, 2012 23:22
Simple Fix for the Webkit Clipped Border-Radius Bug
.list-container {
border-radius: 5px;
border: 1px solid #C5C5C5;
box-shadow: inset 0 1px 0 #FFF;
}
ol {
border: 1px solid transparent;
}
@daemianmack
daemianmack / rails_engines.md
Created July 20, 2012 16:44 — forked from westonplatter/controller_to_be_included.rb
using ActiveSupport::Concerns to extend Rails

Gist to describe the process of adding a namespaced isolated Rails Engine
to a typical Rails application and adding methods to one of the Rails Engine's
controller and model.

Index

  1. Rails applicaiton all by itself.
  2. Rails application with the Rails Engine (FooBar) mounted.
  3. Rails applicaiton partially extending a controller/model from the Rails Engine.
@nrrrdcore
nrrrdcore / frontage.css
Created May 23, 2012 08:21
Outlined Type Effect with CSS Text-Shadowing
body {
background-color: #FFF;
}
#wrapper {
width: 90%;
margin: 200px auto;
}
h1 {
@stevenh512
stevenh512 / apple-shadow.css
Created May 18, 2012 22:16 — forked from nrrrdcore/apple-shadow.css
Bending Shadows Backwards: Apple.com's Container CSS Sorcery
.shadow-stuff {
-moz-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-webkit-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-moz-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
-webkit-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
box-shadow: rgba(0,0,0,.30) 0 2px 3px;
}
.container {